0
点赞
收藏
分享

微信扫一扫

Marshal's confusion

Sky飞羽 2022-07-12 阅读 25


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 条评论