HDU 2139 Calculate the formula

Posted zlrrrr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 2139 Calculate the formula相关的知识,希望对你有一定的参考价值。

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
", s[N]);
    }

    return 0;
}

  

以上是关于HDU 2139 Calculate the formula的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1008 u Calculate e

HDU 2114 Calculate S(n)(公式)

Hdu 1012 u Calculate e

HDU 1012 u Calculate e(简单阶乘计算)

J - Calculate the formula

HDU - 2114 Calculate S(n)