Hust oj 1196 Marshal's confusion II(公式)

来源:互联网 发布:好看的女装品牌 知乎 编辑:程序博客网 时间:2024/05/16 11:25
Marshal's confusion IITime Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 258(95 users)Total Accepted: 84(76 users)Rating: Special Judge: NoDescriptionone day, Marshal want to show the answer :Calculate S(n).
S(n)=1^3+2^3 +3^3 +......+n^3 .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 Input1
2Sample Output0001

0009

公式:S(n)=1^3+2^3 +3^3 +......+n^3=[n(n+1)/2]^2

#include<cstdio>#include<iostream>#include<cmath>using namespace std;typedef long long int ll;ll n;int main(){    while(~scanf("%lld",&n))    {        n %= 10000;        ll a = (n + 1)*n/2;        printf("%04lld\n",a*a%10000);    }}


0 0