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. wait();notify();简单例子

    public class Test1{ /** * @param args */ public static void main(String[] args) { new Thread(new Thr ...

  2. vue 整体引入 mint-ui 样式失败

    当引入Mint-ui 整体css 时 如果出现了这样的错误, 是指找不到对应的Mint-UI 的css :需要从node_modules里寻找 解决方法是在webpack.config.js(有的项目 ...

  3. JS 创建对象总结

    狭义:new 构造函数. (注:在JS中创建对象只有一种方式,就是new 构造函数.其中字面量的方式是一种语法糖,本质仍然是new 构造函数) 广义:工厂模式(解决复杂度) 构造函数模式(解决复杂度, ...

  4. 一条sql 执行查询列表 返回分页数据以及总数 totalCount

    SELECT ID,Name,Age,Addr,Tel,COUNT(1) OVER() AS totalFROM dbo.Student WHERE Age>22 ORDER BY id DES ...

  5. 我的名字叫hadoop

      第一回 新入环境 我的名字是hadoop,我一出生我的爸爸雅虎就给我取了这样一个名字:hadoop,我也不知道为什么叫这个名字,刚出生没多久,雅虎爸爸就把我领进一个黑暗的屋子里面,屋里堆满了黑色的 ...

  6. openWrt libubox组件之uloop原理分析

    1.    libubox概述 libubox是openwrt新版本中的一个基础库,有很多应用是基于libubox开发的,如uhttpd,netifd,ubusd等. libubox主要提供以下两种功 ...

  7. kubernetes基础使用

    查看节点详细信息 kubectl describe node vm2 显示版本号 kubectl version Client Version: version.Info{Major:"1& ...

  8. java并发(1)

    hashmap效率高单线程不安全,hashTable效率低但线程安全 因为hashTable使用synchronized来保证线程安全,所以效率十分低,比如线程1使用put插入数据时,线程2既不能使用 ...

  9. ov5640介绍

    1 摄像头 在各类信息中,图像含有最丰富的信息,作为机器视觉领域的核心部件,摄像头被广泛地应用在安防.探险以及车牌检测等场合.摄像头按输出信号的类型来看可以分为数字摄像头和模拟摄像头,按照摄像头图像传 ...

  10. mfc通过MapWinGIS控件读取shp文件(通过#import实现)

    在MFC工程中想使用MapWinGIS组件,有多种方法可以实现, 第一种方法,#Import来实现 1.首先注册MapWinGIS ActiveX组件, 2.新建一个单文档工程:MapGis,为控件添 ...