hdu 2114 Calculate S(n)

hdu 2114 Calculate S(n)

Problem DescriptionCalculate S(n).

S(n)=13+23 +33 +......+n3 .  InputEach line will contain one integer N(1 < n < 1000000000). Process to end of file.  OutputFor each case, output the last four dights of S(N) in one line.
  Sample Input12  Sample Output00010009

以下代码对支持longlong的编译器可通过:

#include<iostream>
using namespace std;
int main()
{
 long long n,i,m;
 while(cin>>n)
 {
  n=n%10000;
  m=n*(n+1)/2%10000;            //数学公式:1^3+2^3+3^3+……+n^3=[n(n+1)/2]^2 
  m=m*m%10000;
  printf("%04d\n",m);
 }
 return 0;
}

原文地址:https://www.cnblogs.com/crazyapple/p/2999499.html