HDU - 6027 Easy Summation

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

 

百度翻译:

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

 

给定两个整数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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值