HDU 2139 Calculate the formula
时间:2018-09-21 14:31:28
收藏:0
阅读:157
http://acm.hdu.edu.cn/showproblem.php?pid=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 <bits/stdc++.h>
using namespace std;
const int maxn = 2345;
long long s[maxn];
int main() {
int N;
s[1] = 1;
for(int i = 3; i <= maxn; i += 2)
s[i] = s[i - 2] + i * i;
while(~scanf("%d", &N)) {
printf("%lld\n", s[N]);
}
return 0;
}
原文:https://www.cnblogs.com/zlrrrr/p/9686151.html
评论(0)