首页 > 其他 > 详细

hdu-2114-Calculate S(n)

时间:2015-08-09 18:55:17      阅读:120      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!