HDU
来源:互联网 发布:淘宝麦麦网 编辑:程序博客网 时间:2024/06/03 16:37
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 sumf(1)+f(2)+...+f(n). The problem is simple as it looks, apart from the value ofn 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) andk(0≤k≤5)
.
Output
For each test case, print a single line containing an integer modulo 109+7
.
Sample Input
3
2 5
4 2
4 1
Sample Output
33
30
10
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long hanshu(long long a,long long n);
int main()
{
int T;
cin>>T;
while(T--)
{
long long n,k;
cin>>n>>k;
long long t;
long long ans=0;
for(t=1;t<=n;t++)
{
ans=ans+hanshu(t,k);
}
cout<<ans%1000000007<<endl;
}
return 0;
}
long long hanshu(long long a,long long n)
{
long long b=1000000007;
long long sum=1;
a%=b;
while(n>0)
{
if(n%2!=0)
sum=(sum*a)%b;
n/=2;
a=(a*a)%b;
}
//cout<<sum<<endl;
return sum;
}
注意:long long输入。
百度翻译:
关于权力的总和,你遇到了一个传统的问题。
给定两个整数n和k,让f(I)= IK,请评估总和F(1)+ F(2)+。这个问题看起来很简单,除了这个问题中n的值是相当大的。
你能找出答案吗?由于答案可能太大,请输出答案模109 + 7
。
输入
输入的第一行包含一个整数T(1≤T≤20),表示测试用例的数目。
下面的T行包含两个整数N(1≤N≤10000)和K(0≤K≤5)
。
输出
对于每个测试案例,打印一行包含一个整数模109 + 7
。
样本输入
三
2 5
4 2
4 1
示例输出
三十三
三十
十
题意:你n,k.
1的k次幂+2的k次幂+...+n的k次幂 和 取模1000000007
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 运维之系统服务篇------2.linux扩展应用 、 vim编辑技巧 、 发布网络YUM源 、 源码编译安装
- HTTP协议学习笔记
- Linux常用操作命令(一)
- 高性能服务器开发复习
- 有恒事竟成
- HDU
- Weblogic控制台忘记密码问题解决方法
- js伪类的css修改方法
- Struts2-day01 环境搭建 源码导入 配置文件 默认action,method 详解Action 封装数据的方式
- HDU 1003 B
- 【转】IntelliJ IDEA Ultimate 2017激活方法
- 每天学一点 mysql
- Linux查找指定一天的文件及统计
- 序列化和反序列化理解