Easy Summation

                                                            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072
K (Java/Others)

                                                                                             Total Submission(s): 27    Accepted Submission(s): 16

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(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).
 
Output
For each test case, print a single line containing an integer modulo 109+7.
 
Sample Input
  1. 3
  2. 2 5
  3. 4 2
  4. 4 1
 
Sample Output
  1. 33
  2. 30
  3. 10
 
Source




——————————————————————————————————

题意:给出一个n和k,求从1^k到n^k的和

解题思路:暴力,注意取模即可

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <map>
  8. #include <cmath>
  9. #include <set>
  10. #include <stack>
  11. #include <queue>
  12. #include <vector>
  13. #include <bitset>
  14. #include <functional>
  15.  
  16. using namespace std;
  17.  
  18. #define LL long long
  19. const int INF=0x3f3f3f3f;
  20. const int mod=1e9+7;
  21.  
  22. int n,m;
  23.  
  24. int main()
  25. {
  26. int T;
  27. scanf("%d",&T);
  28. while(T--)
  29. {
  30. scanf("%d%d",&m,&n);
  31. LL ans=0;
  32. for(int i=1; i<=m; i++)
  33. {
  34. LL x=1;
  35. for(int j=1; j<=n; j++)
  36. {
  37. x*=i;
  38. x%=mod;
  39. }
  40. ans+=x;
  41. ans%=mod;
  42. }
  43. printf("%lld\n",ans);
  44. }
  45. return 0;
  46. }


HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏的更多相关文章

  1. Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏

    Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...

  2. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  3. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  4. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  5. HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏

    Deleting Edges                                                                                  Time ...

  6. HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏

    Graph Theory                                                                 Time Limit: 2000/1000 M ...

  7. POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15478   Accepted: 67 ...

  8. Avro基础 分类: C_OHTERS 2015-02-14 19:56 310人阅读 评论(0) 收藏

    一.Avro的基本功能 1.定义了数据模式文件的语法,一般使用json文件.以及一些数据基本类型与复杂类型. 2.定义了数据序列化到文件后的数据格式,此格式可供各种语言进行读取. 3.为部分语言定义了 ...

  9. Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏

    1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...

随机推荐

  1. 关于Git的礼节

    (这里的内容本来是<怎样尊重一个程序员>的一小节,但由于Git的使用引起了很普遍的不尊重程序员的现象,现在特别将这一节提出来单独成文.) Git是现在最流行的代码版本控制工具.用外行话说, ...

  2. javascript获取事件源对象和产生事件的对象

    事件源对象是指event对象,其封装了与事件相关的详细信息,比如按键状态. 获取事件源对象的方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  3. Ansible develop module

    def cnf(action,configs,path): message = "Modify %s\n" %path changed = False if action == & ...

  4. The Hard Thing About Hard Things

    1.大多数的管理书籍都是告诉你如何做正确的事,不把事情搞砸.而好书是告诉你,当事情已经搞砸时,你该怎么办. 2.这是个个真实的世界,他们偷走了你的梦想,可你却不知道是谁偷的.

  5. GridView中如何实现自定义时间货币等字符串格式?

    方法一: <asp :GridView ID="GridView1" runat="server"> <columns> <asp ...

  6. 条款2:尽量以const, enum, inline替换#define

    原因: 1. 追踪困难,由于在编译期已经替换,在记号表中没有. 2. 由于编译期多处替换,可能导致目标代码体积稍大. 3. define没有作用域,如在类中定义一个常量不行. 做法: 可以用const ...

  7. python内置函数之attr【反射】

    #Auther Bob#--*--conding:utf-8 --*-- #我们来循序渐进的学习反射 import s1 #阶段1# def run():# url = input("请输入 ...

  8. jquery源码学习-初始(1)

    最近几天一直在研究jquery源码,由于水平太低看得昏头转向.本来理解的也不是很深刻,下面就用自己的想法来说下jquery是如何定义构造函数初始化的.如果有什么不对的地方,希望个位高手指出. 首先要了 ...

  9. 把Linq查询返回的var类型的数据 转换为DataTable EF连接查询

    问题:我要获得一个角色下对应的所有用户,需要两表连接查询,虽然返回的只有用户数据,但是我想到若是返回的不只是用户数据,而还要加上角色信息,那么我返回什么类型呢,返回var吗,这样不行. 于是我网上找找 ...

  10. 绘制3D的js库

      有哪些值得推荐的绘制3D的js库?   4 个回答 默认排序​ 草皮子 HTML5/GAME 4 人赞同了该回答 只用过three.js,所以推荐这个.不清楚你打算用来做什么,总的来说,得看你的运 ...