您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: