HDU - 6027 Easy Summation
2017-10-14 14:06
821 查看
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 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 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) and
k(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的值是相当大的。
你能找出答
4000
案吗?由于答案可能太大,请输出答案模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
Given two integers n and k. Let f(i)=ik, 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 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) and
k(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的值是相当大的。
你能找出答
4000
案吗?由于答案可能太大,请输出答案模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 6027 Easy Summation
- (HDU 6027 女生专场)Easy Summation 水题 预处理
- HDU - 6027 Easy Summation
- HDU 6027 Easy Summation
- HDU 6027 Easy Summation【简单相加||快速幂】
- HDU 6027 Easy Summation
- HDU 6027 Easy Summation (gcd)
- HDU 6027 Easy Summation
- HDU - 6027-Easy Summation
- hdoj 6027 Easy Summation
- 杭电6027 Easy Summation
- hdu 6027 水题 注意全程取模,全程long long
- HDU-1004 Let the Balloon Rise(map)
- HDU 5211 Mutiple
- HDU-1150-Machine Schedule【最小点覆盖】【二分图匹配】
- HDU 3348 By Assassin [可怕的模拟题]
- hdu 4309 状压+最大流
- hdu 1239 水题
- hdu 2126 DP
- HDU:2042不容易系列之二解题报告