HDU - 6027 Easy Summation(快速幂)解题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 6027 Easy Summation(快速幂)解题相关的知识,希望对你有一定的参考价值。
Easy Summation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1107 Accepted Submission(s): 443
Problem Description
You are encountered with a traditional problem concerning the sums of powers.
Given two integers n and k . Let f(i)=ik , please evaluate the sum f(1)+f(2)+...+f(n) . The problem is simple as it looks, apart from the value of n in this question is quite large.
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7 .
Given two integers n and k . Let f(i)=ik , please evaluate the sum f(1)+f(2)+...+f(n) . The problem is simple as it looks, apart from the value of n in this question is quite large.
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7 .
Input
The first line of the input contains an integer T(1≤T≤20)
, denoting the number of test cases.
Each of the following T lines contains two integers n(1≤n≤10000) and k(0≤k≤5) .
Each of the following T lines contains two integers n(1≤n≤10000) and k(0≤k≤5) .
Output
For each test case, print a single line containing an integer modulo 109+7
.
Sample Input
3
2 5
4 2
4 1
Sample Output
33
30
10
标准快速幂~~~
1 #include <stdio.h> 2 long long kuaisumi(long long a,int b) 3 { 4 long long c=1,base=a; 5 while(b) 6 { 7 if(b&1) 8 { 9 c=c*a%1000000007; 10 } 11 a=a*a%1000000007; 12 b>>=1; 13 } 14 return c; 15 } 16 int main() 17 { 18 int t,a,b,i,c; 19 long long sum; 20 scanf("%d",&t); 21 while(t--) 22 { 23 sum=0; 24 scanf("%d%d",&a,&b); 25 for(i=1;i<=a;i++) 26 { 27 c=kuaisumi(i,b); 28 sum=(sum+c)%1000000007; 29 } 30 printf("%lld\n",sum); 31 } 32 return 0; 33 }
以上是关于HDU - 6027 Easy Summation(快速幂)解题的主要内容,如果未能解决你的问题,请参考以下文章