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输入。

 

百度翻译:

关于权力的总和,你遇到了一个传统的问题。

 

给定两个整数nk,让fI= IK,请评估总和F1+ F2+。这个问题看起来很简单,除了这个问题中n的值是相当大的。

 

你能找出答案吗?由于答案可能太大,请输出答案模109 + 7

 

 

输入

 

输入的第一行包含一个整数T1T20),表示测试用例的数目。

 

下面的T行包含两个整数N1N10000)和K0K5

 

 

输出

 

对于每个测试案例,打印一行包含一个整数模109 + 7

 

 

样本输入

 

 

2 5

 

4 2

 

4 1

 

示例输出

 

三十三

 

三十

 

 

题意:你n,k.

1k次幂+2k次幂+...+nk次幂   和   取模1000000007

原创粉丝点击