UVA - 11401——Triangle Counting(推公式)

题目链接:https://vjudge.net/problem/UVA-11401

#include
#include
#include
using namespace std;
long long f[1000010];
int main()
{
    for(long long i=4;i<=1000000;i++)
    {
        f[i]=f[i-1]+((i-1)*(i-2)/2-(i-1)/2)/2;
    }
    int n;
    while(scanf("%d",&n),n>2)
    {
        printf("%lld\n",f[n]);
    }
}

 

你可能感兴趣的:(ACM白书)