标签:数论
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:数论
原文地址:http://blog.csdn.net/bestcoder_judge/article/details/47377469