前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【CSU 1556】Pseudoprime numbers

【CSU 1556】Pseudoprime numbers

作者头像
饶文津
发布2020-05-31 23:37:22
3380
发布2020-05-31 23:37:22
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏

Description

?Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is

1^m + 2^m + 3^m + …… + n^m

But Jerry’s mathematics is poor, help him to escape from the room.

Input

?There are some cases (about 500). For each case, there are two integer numbers n, m describe as above ( 1 <= n < 1 000 000, 1 <= m < 1000).

Output

?For each case, you program will output the answer of the sum of the sequence of number (mod?1e9+7).

Sample Input

代码语言:javascript
复制
代码语言:javascript
复制
4 1
5 1
4 2
5 2
4 3

Sample Output

代码语言:javascript
复制
代码语言:javascript
复制
10
15
30
55
100

题意:求1^m + 2^m + 3^m + …… + n^m ?(mod?1e9+7)

注意:每个加起来的时候和加起来后也要mod

代码语言:javascript
复制
#include<stdio.h>
#define M 1000000007
long long qpow(long long a,long long m)//快速幂
{
    long long ans=1,k=a;
    while(m)
    {
        if(m&1)
            ans=(ans*k)%M;
        k=(k*k)%M;
        m>>=1;
    }
    return ans;
}
int main()
{
    long long n,m,ans;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        ans=0;
        for(int i=1; i<=n; i++)
            ans+=qpow(i,m)%M;//这里mod一下
        printf("%lld\n",ans%M);//这里mod一下
    }
    return 0;
}
本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-02-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com