本文主要是介绍Calculate the formula 2139,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
#include <cstdio>
int main(int argc, const char* argv[])
{
__int64 n;
while (scanf("%I64d", &n) == 1)
{
n = (n>>1) + 1;
printf("%I64d\n", n*(2*n+1)*(2*n-1)/3);
}
return 0;
}
这篇关于Calculate the formula 2139的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!