码迷,mamicode.com
首页 > 其他好文 > 详细

hdu-2114-Calculate S(n)

时间:2015-08-09 18:57:25      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:数论

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu-2114-Calculate S(n)

标签:数论

原文地址:http://blog.csdn.net/bestcoder_judge/article/details/47377469

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!