目录
MARSHAL'S CONFUSION II

** MARSHAL'S CONFUSION II:** <Excerpt in index | 首页摘要>

<The rest of contents | 余下全文>

Marshal’s confusion II
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 239(80 users) Total Accepted: 73(66 users) Rating: Special Judge: No
Description
one day, Marshal want to show the answer :Calculate S(n). S(n)=1^3+2^3 +3^3 +……+n^3 .
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

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<cmath>
#include<queue>
#include<iostream>
using namespace std;
const int m=10000;
typedef long LL;
int main()
{
LL n;
while(~scanf("%ld",&n))//1^3+2^3+...+n^3=[n(n+1)/2]^2
{
LL a;
a=n*(n+1)/2%m;
LL sum=a*a%m;
printf("%04d\n",sum);
}
return 0;
}
文章作者: 爱笑的k11
文章链接: http://1315402725.github.io/posts/a34e5bf7/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱笑的k11
打赏
  • 微信
  • 支付寶

评论