Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
看到这个时间,我懵逼了。。。
果然,Java就是打表,都不能AC,因为Java的输入是流,需要的时间比C真的长好多。。。。

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

简单题,就不翻译了。
附上AC的C语言代码:

#include<iostream>
const int MAX=2345;
//计算2345正好大于2^31-1,输入输出用scanf和printf不能cin和cout不然超时
__int64 db[MAX];
using namespace std;
int main()
{
    int n,m,i;
    db[1]=1;
    //打表法 
    for(i=3;i<=MAX;i+=2)
    {
        db[i]=db[i-2]+i*i;
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%I64d\n",db[n]);
    }
    return 0;
}
posted on 2016-05-05 01:57  cnxo  阅读(130)  评论(0编辑  收藏  举报