当前位置:首页 > 综合 > 综合

csu 1556: Jerry's trouble(高速幂)

优良自学吧提供csu 1556: Jerry's trouble(高速幂),csu 1556: Jerry's trouble(快速幂) 1556: Jerry's trouble Time Limit: 10 Sec  Memory Limit: 256 MB Submit: 445  Solved: 190 [Submit][

csu 1556: Jerry's trouble(快速幂)

1556: Jerry's trouble

Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 445  Solved: 190
[Submit][Status][Web Board]

Description

 Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is

But Jerry’s mathematics is poor, help him to escape from the room.

Input

 There are some cases (about 500). For each case, there are two integer numbers n, m describe as above ( 1 <= n < 1 000 000, 1 <= m < 1000).

Output

 For each case, you program will output the answer of the sum of the sequence of number (mod 1e9+7).

Sample Input

4 1
5 1
4 2
5 2
4 3

Sample Output

10
15
30
55
100

HINT


求1到n之间,所有数的m次幂之和。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define Mod 1000000007
#define ll long long

using namespace std;

ll pow_mod(ll a,ll b) {
    ll res=1;
    while(b) {
        if(b&1)
            res*=a,res%=Mod;
        a*=a;
        a%=Mod;
        b>>=1;
    }
    return res;
}
ll n,m;

int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        ll ans=0;
        for(int i=1; i<=n; i++) {
            ans+=pow_mod(i,m);
            ans%=Mod;
        }
        printf("%lld\n",ans);
    }
}



(本文来自互联网,不代表搜站(http://www.ylzx8.cn/)的观点和立场)
本站所有内容来自互联网,若本站收录的信息无意侵犯了贵司版权,请给我们来信(ylzx8cn@163.com),我们会及时处理和回复,谢谢

最近更新