首页 > 其他 > 详细

HDU - 6027 Easy Summation(快速幂)解题

时间:2017-07-19 12:39:09      阅读:201      评论:0      收藏:0      [点我收藏+]

                      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 .
 

 

Input
The first line of the input contains an integer T(1T20) , denoting the number of test cases.
Each of the following T lines contains two integers n(1n10000) and k(0k5) .
 

 

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(快速幂)解题

原文:http://www.cnblogs.com/lyf0031/p/7204864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!