CSU 1556 快速幂

来源:互联网 发布:miss淘宝店网址多少 编辑:程序博客网 时间:2024/05/20 04:27

J - J
Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%lld & %llu
Submit Status Practice CSU 1556

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 15 14 25 24 3

Sample Output

10153055100



题解:题意很难看懂,或者根本看不懂,给个第一个样例吧:1^1+2^1+3^1+4^1=10;大概就是这样


题解:快速幂就可以了


#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<set>#include<vector>#include<map>using namespace std;#define maxn 100001#define LL long long#define CLR(x) memset(x,0,sizeof(x))#define mod 1000000007LL pow_mod(LL a,LL n,LL m){if(n==0)return 1;LL x=pow_mod(a,n/2,m);LL ans=x*x%m;if(n%2==1)ans=ans*a%m;return ans;}int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifLL x,y;while(~scanf("%lld%lld",&x,&y)){LL sum=0;for(LL i=1;i<=x;i++){sum+=pow_mod(i,y,mod);}printf("%lld\n",sum%mod);}return 0;}




0 0