hdu 2114 Calculate S(n) 数论(简单题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114

自己对数论一窍不通啊现在,做了一道水题,贴出来吧。。。主要是让自己记住这个公式:

前n项和的立方公式为   : s(n)=(n*(n+1)/2)^2;

 前n项和的平方公式为:s(n)=n*(n+1)(2*n+1)/6;

代码:

 1     #include<iostream>
 2 #include<cstdlib>
 3 #include<cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7         long long int ans;
 8         long long int n;
 9         while(scanf("%lld",&n)!=EOF)
10         {
11         
12         ans=(((n*(n+1)/2)%10000)*((n*(n+1)/2)%10000))%10000;
13         printf("%04lld
",ans);
14         }
15        return 0;
16 }
View Code
原文地址:https://www.cnblogs.com/xiaozhuyang/p/hdu2114.html