2017年ACM第八届山东省赛G题:sum of power
2017-10-06 15:22
351 查看
G: sum of power
题目描述
Calculate![](https://images2017.cnblogs.com/blog/1225186/201710/1225186-20171006151008271-540472980.png)
mod (1000000000+7) for given n,m.
输入
Input contains two integers n,m(1≤n≤1000,0≤m≤10).输出
Output the answer in a single line.样例输入
10 0
样例输出
10 题意:累加从 1 到 n 的 m次幂模 思路:不用快速幂都能过 还要什么思路。。。。。
#include <cstdio> #include <iostream> #include <algorithm> using namespace std ; #define mod 1000000007 #define LL long long LL quick_mod(LL n , LL m){ LL result = 1 ; while(m){ if(m&1){ result = (result * n )%mod ; } n = (n*n) %mod; m>>=1 ; } return result %mod; } int main(){ int n , m ; while(~scanf("%d%d" , &n , &m)){ LL result = 0 ; for(int i=1 ; i<=n ; i++){ result = (result+quick_mod(i , m) ) %mod ; } printf("%lld\n" , result) ; } return 0 ; }
#include <cstdio> #include <iostream> #include <algorithm> using namespace std ; #define LL long long #define mod 1000000007 int main(){ LL n , m ; while(~scanf("%lld%lld" , &n , &m)){ LL result = 0 ; for(int i=1 ; i<= n ; i++){ LL num = 1 ; for(int j=1 ; j<=m ; j++){ num = num * i %mod ; // i ^ m % mod } result = (result + num ) % mod ; } printf("%lld\n" , result) ; } return 0 ; }
相关文章推荐
- ACM第八届山东省赛 G-Sum of power
- 山东省第八届ACM省赛 G 题 sum of power 解答
- 山东省第八届 ACM 省赛 sum of power(SDUT 3899)
- 2017年ACM第八届山东省赛A题:Return of the Nim
- 山东省第八届 ACM 省赛 sum of power (求和、水)
- ACM 第八届山东省赛 A题 Return of the Nim
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- 山东省第八届ACM省赛A.Return of the Nim
- 山东省第八届ACM省赛 G 题(sum of power)
- 2017年山东省第八届ACM竞赛总结
- 2017年ACM第八届山东省赛K题:CF
- 山东省第八届 ACM 省赛 G sum of power (简单快速幂)
- 2017年ACM第八届山东省赛J题:company
- 2017年ACM第八届山东省赛I题: Parity check(判断 第n项斐波那契数列奇偶性)
- 2017年山东省第八届ACM大学生程序设计竞赛 B Quadrat(sdut 3894) 打表找规律
- 2017年ACM第八届山东省赛F题:quadratic equation(离散数学蕴含式)
- 山东省第八届acm省赛 Return of the Nim
- 2017年山东省第八届ACM大学生程序设计竞赛总结
- 2017年第八届山东省ACM大学生程序设计竞赛后记
- [置顶] 2017年山东省第八届acm省赛总结