Description

You are encountered with a traditional problem concerning the sums of powers. 
Given two integers $n$ and $k$. Let $f(i)=i^k$, 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 $10^9+7$.
 

Input

The first line of the input contains an integer $T(1\leq T\leq20)$, denoting the number of test cases. 
Each of the following $T$ lines contains two integers $n(1\leq n\leq 10000)$ and $k(0\leq k\leq 5)$. 
 

Output

For each test case, print a single line containing an integer modulo $10^9+7$.
 

Sample Input

3
2 5
4 2
4 1
 

Sample Output

33
30
10
 
 
题目意思:给定两个数n,k。求1的k次方 + 2的k次方 + ....+ n的k次方。结果会很大,所以要对10的9次方+7取余。
 
解题思路:把1-n的每个数的k次方加起来,求幂的时候使用快速幂,值得一提的是数非常大,因此在快速幂求幂的过程中, 每一步也要对10的9次方+7取余。
 
 #include<stdio.h>
#define MAX 1000000007
#define ll long long int
ll test(int n,int k)
{
ll i,t;
t=;
for(i=; i<=k; i++)
{
t=(t*n)%MAX;
}
return t;
}
int main()
{
ll n,k,sum,i,t;
while(scanf("%lld",&t)!=EOF)
{
while(t--)
{
sum=;
scanf("%lld%lld",&n,&k);
for(i=; i<=n; i++)
{
sum=(sum+test(i,k))%MAX;
}
printf("%lld\n",sum);
}
}
return ;
}
 
 
 

Easy Summation的更多相关文章

  1. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  2. hdu6027Easy Summation(快速幂取模)

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

  3. CUDA编程(十)使用Kahan&#39;s Summation Formula提高精度

    CUDA编程(十) 使用Kahan's Summation Formula提高精度 上一次我们准备去并行一个矩阵乘法.然后我们在GPU上完毕了这个程序,当然是非常单纯的把任务分配给各个线程.也没有经过 ...

  4. 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优

    libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...

  5. Struts2 easy UI插件

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  6. Easy UI常用插件使用

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  7. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  8. CodeForces462 A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. easy ui插件

    简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...

随机推荐

  1. 复习宝典之Git分布式版本控制

    查看更多宝典,请点击<金三银四,你的专属面试宝典> 第三章:Git分布式版本控制 1)git文件状态 git中的文件有以下几种状态: 未跟踪(untrack):表示文件为新增加的. 已修改 ...

  2. parsing XML document from class path resource [applicationtext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationtext.xml] cannot be opened because it does not e

    控制台异常: parsing XML document from class path resource [applicationtext.xml]; nested exception is java ...

  3. JavaBen 中 如何将字段设置为 "text" 文本类型

    @Lob @Column(name="FEEDBACK_MESSAGE",columnDefinition="TEXT", nullable=true) pub ...

  4. $.extend() 合并问题

  5. 坑爹的jquery ui datepicker

    1.坑爹的jquery ui datepicker 竟然不支持选取时分秒,害的我Format半天 期间尝试了bootstrap的ditepicker,但是不起作用,发现被jquery ui 覆盖了, ...

  6. Vue性能优化之组件按需加载(以及一些常见的性能优化方法)

    关于Vue中的按需加载我就简单介绍一下:大概就是我们所有的东西都会在app.js里面,但是我们并不需要把所有的组件都一次性加载进来,我们可以在需要它的时候再将它加载进来,话不多说,开车! 1.webp ...

  7. 课时133.margintop失效原因(理解)

    我们之前讲过如果只有子元素设置了margin top而父元素没有边框则会跟着被顶下来的. 而我们怎么解决这个问题呢? 就是给父元素设置一个边框 而为什么我们在第二个浮动的盒子设置边框没有用呢?应为第一 ...

  8. 动态代理以及对应Spring中AOP源码分析

    AOP(面向切面编程)在Spring中是被广泛应用的(例如日志,事务,权限等),而它的基本原理便是动态代理. 我们知道动态代理有两种:基于JDK的动态代理以及基于CGlib动态代理.以下是两种动态代理 ...

  9. Address already in use: JVM_Bind,tomcat启动异常

    严重: StandardServer.await: create[8050]: java.net.BindException: Address already in use: JVM_Bind tom ...

  10. 佛山Uber优步司机奖励政策(12月14日到12月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...