Description
Calculate S(n).
1
2
Calculate S(n).
S(n)=1^3+2^ 3 +3 ^3 +......+n^ 3 .
Each line will contain one integer N(1 < n < 1000000000). Process to end of file.
For each case, output the last four dights of S(N) in one line.
1
2
Sample Output
0001
0009
分析:立方和:s=(n*(1+n)/2)^2 或者s=(1+2+……n)^2
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>
using namespace std;
int main()
{
int n;
__int64 sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
n%=10000;
sum=(((1+n)*n)/2)%10000;
sum=sum*sum%10000;
cout<<setw(4)<<setfill('0')<<sum<<endl;
}
return 0;
}