Marshal's confusion

Sky飞羽

关注

阅读 25

2022-07-12


Marshal’s confusion

one day, Marshal want to show the answer : 12+32+5^2+……+ n ^2.
please tell to him.

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 <stdio.h>
int main(void)
{
long n;
while(scanf("%ld", &n) == 1)
{
long sum = 0;
for(int i = 1; i <= n; i += 2)
{
sum += pow(i, 2);
}
printf("%ld\n", sum);
}
}

pow(a,b):a^b


精彩评论(0)

0 0 举报