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. PHP中call user func()和call_user_func_array()调用自定义函数小结

    call_user_func() 和 call_user_func_array(),通过传入字符串函数,可以调用自定义函数,并且支持引用,都允许用户调用自定义函数并传入一定的参数: 1.mixed c ...

  2. .Net Core使用Redis-从安装到使用

    一.安装 本文使用的操作系统是Centos7 在Redis中文网下载最新的Redis压缩包:http://www.redis.cn/ 把包上传到Liunx服务器上,cd 到包所在的目录执行以下命令 # ...

  3. 配置一个nginx反向代理&负载均衡服务器

    一.基本信息 系统(L):CentOS 6.9 #下载地址:http://mirrors.sohu.com 反代&负载均衡(N):NGINX 1.14.0 #下载地址:http://nginx ...

  4. Flink+Kafka整合的实例

    Flink+Kafka整合实例 1.使用工具Intellig IDEA新建一个maven项目,为项目命名为kafka01. 2.我的pom.xml文件配置如下. <?xml version=&q ...

  5. s3c2440串口详解

    一.UART原理说明 通用异步收发器简称UART(Universal Asynchronous Receiver/Transmitter),它用来传输串行数据:发送数据时,CPU将并行数据写入UART ...

  6. python3的下载与安装

    python3的下载与安装 1.首先,从Python官方网站:http://python.org/getit/ ,下载Windows的安装包 ython官网有几个下载文件,有什么区别?Python 3 ...

  7. 《AngularJS学习整理》系列分享专栏

    <AngularJS学习整理>系列分享专栏   <AngularJS学习整理>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/re ...

  8. categorical[np.arange(n), y] = 1 IndexError: index 2 is out of bounds for axis 1 with size 2

    我的错误的代码是:train_labels = np_utils.to_categorical(train_labels,num_classes = 3) 错误的原因: IndexError: ind ...

  9. 安装使用supervisor来启动服务

    supervisor 使用方法 supervisor(官网)是一个unix的系统进程管理软件,可以用它来管理apache.nginx等服务, 若服务挂了可以让它们自动重启.当然也可以用来实现golan ...

  10. linux之sed基础命令详解

    sed (Stream  EDitor)是一个强大的字符流编辑器,输入一般是来自文件,默认情况下不编辑原文件,仅对模式空间中的数据作处理;而后,将模式空间打印到屏幕显示 sed基础用法 sed [op ...