您的位置:首页 > 其它

hdu-2114-Calculate S(n)

2015-08-09 16:53 495 查看
Calculate S(n).

S(n)=13+23 +33 +……+n3 .

Input

Each line will contain one integer N(1 < n < 1000000000). Process to end of file.

Output

For each case, output the last four dights of S(N) in one line.

Sample Input

1

2

Sample Output

0001

0009

前n项立方和的公式:(n*(n+1)/2)^2;,注意这里要用__int64,用int会一直WA

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
__int64 n,i;
while(cin>>n)
{
n=n%10000;
i=(((n*(n+1)/2))*((n*(n+1)/2)))%10000;
printf("%04I64d\n",i);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: