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. Python入门 —— 06语音识别

    Python 语音 实现语音操控的原理 语音操控分为语音识别和语音朗读两部分 我们使用speech模块实现语音模块(python 2.7) SAPI是微软Speech API , 是微软公司推出的语音 ...

  2. js实现99乘法表的编写(双层for循环与递归方法)

    双层for循环实现方法: function nine (num) { ; i <= num; i++){ var str = ''; ; k <= num; k++){ if(i > ...

  3. windows简易使用composer 安装国内镜像

    1.下载composer.phar文件 地址: https://getcomposer.org/download/  从下面选择一个 2.下载成功,新建项目(找到已有的项目文件夹)文件夹(D:\PHP ...

  4. PHP封装CURL

    CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数,并且支持HTTPS ...

  5. java语言描述 用递归打印字符串

    public class Test{ static private int n; public static void main(String[] args) { Test.n=76234; if(n ...

  6. Springboot 拦截器(HandlerInterceptorAdapter)中注入无效

    1,传统filter和HandlerInterceptorAdapter的区别 springboot对传统Filter进行增强,添加更多细粒度的操作,分别实现预处理.后处理(调用了Service并返回 ...

  7. HDOJ:1533-Going Home(最小费用流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 解题心得: 第一次写最小费用流的题,去hdoj上找了一个入门级题目,建图比较简单,用了spfa和 ...

  8. SQL 备忘录

    都兼容 MySQL 查看表结构:DESC ${table_name} 查看建表语句:SHOW CREATE TABLE ${table_name} ​表增加列:ALTER TABLE ${table_ ...

  9. ASP.NET MVC 微信JS-SDK认证

    layout: post title: ASP.NET MVC 微信JS-SDK认证 category: .net date: 2016-11-01 00:00:00 tags: .net javas ...

  10. 《绝地求生大逃杀》BE错误怎么办 BE服务未正常运行及安装失败解决方法

    <绝地求生大逃杀>BattlEye Launcher是游戏的反作弊程序,也是启动过程中做容易出现错误的,今天小编带来“爆锤吧务”分享的<绝地求生大逃杀>BE服务未正常运行及安装 ...