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

Marshal's confusion II

时间:2015-11-25 00:23:19      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

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

 

Marshal's confusion II

标签:

原文地址:http://www.cnblogs.com/beige1315402725/p/4993354.html

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