HDU 2114 水题

来源:互联网 发布:wish产品优化技巧 编辑:程序博客网 时间:2024/05/17 01:03
 

Calculate S(n)

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3651    Accepted Submission(s): 1414


Problem Description
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
12
 

Sample Output
00010009
 

Author
天邪
 

Source
HDU 2007-10 Programming Contest_WarmUp
 
不用写java
 
因为这里分母比较小 等于4
所以只需要把取余的10000变成40000
然后最后把答案/4即可。
PS:此法不适合分母特别大的情况。
一般的,取余的数往往是一个质数,所以应该求逆元
 
但是这里不互质,所以才这么做的。恩
 
 
我的代码:(很短)
#include<stdio.h>int main(){__int64 n,ans;while(scanf("%I64d",&n)!=EOF){ans=(n*n%40000)*((n+1)*(n+1)%40000)%40000;ans=ans/4;printf("%04I64d\n",ans);}return 0;}