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;
}

相关文章:

  • 2021-08-26
  • 2021-12-08
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-01-03
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案