首页 > 其他 > 详细

HDU 2139 Calculate the formula

时间:2018-09-21 14:31:28      阅读:159      评论:0      收藏:0      [点我收藏+]

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;
}

  

HDU 2139 Calculate the formula

原文:https://www.cnblogs.com/zlrrrr/p/9686151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!