11401-triangle counting
Time limit:1.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=469&page=show_ problem&problem=2396
You are given n rods of length 1, 2 ..., N. You are have to pick any 3 of the them & build a triangle. How many distinct triangles can your make? Note that, two triangles'll be considered different if they have in least 1 pair of arms with different length.
Input
The input for each case would have only a single positive integer n (3<=n<=1000000). The end of input is indicated by a case with n<3. This case should is processed.
Output
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45374.htm
For the all test case, print the number of distinct triangles you can make.
Sample input Output for sample input
First of all, when the maximum edge for x of the number of matches, and then the recurrence of the cumulative can be. (Because the problem is to calculate the number of sides of the length of no more than N)
Complete code:
/*0.029s*/
#include <cstdio>
long long f[1000010];
int main ()
{
f[3] = 0;
For (long long x = 4; x <= 1000000 ++x)
f[x] = f[x-1] + ((x-1) * (x-2)/2-(X-1)/2)/2;
int n;
while (scanf ("%d", &n), n >= 3)
printf ("%lld\n", F[n]);
return 0;
}