Calculate the formula
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4707 Accepted Submission(s): 1404
Problem Description
You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.
Input
In each case, there is an odd positive integer n.
Output
Print the sum. Make sure the sum will not exceed 2^31-1
Sample Input
3
Sample Output
10
知道公式就好了。另外,用__int64
AC代码:
#include<iostream>
using namespace std;
int main()
{
__int64 n;
while(scanf("%I64d",&n)!=EOF)
{
printf("%I64d\n",((n+1)*(n*n+2*n))/6);
}
return 0;
}