Problem Description
Calculate mod (1000000000+7) for given n,m.
Input
Input contains two integers n,m(1≤n≤1000,0≤m≤10).
Output
Output the answer in a single line.
Sample Input
10 0
Sample Output
10
Hint
Source
"Inspur Cup" Shandong Province 8th ACM College Student Programming Competition (Thanks to Qingdao University of Science and Technology)
Question: Find the sum of the m-th powers of the integers from 1 to n
Idea: fast power, pay attention to use long loog
Code:
#include<cstdio> #include<cstring> #include<algorithm> #define mod 1000000007 using namespace std; typedef long long LL; LL q_pow(LL x,LL y){ LL ans=1; while(y){ if(y&1) ans=ans*x%mod; x=x*x%mod; y>>=1; } return ans%mod; } int main(){ LL n,m; scanf("%lld%lld",&n,&m); LL ans=0; for(LL i=1;i<=n;i++){ ans+=q_pow(i,m)%mod; ans% = mod; } printf("%lld\n",ans); return 0; }