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


4 1
5 1
4 2
5 2
4 3

Sample Output


10
15
30
55
100

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

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

#include<stdio.h>
#define M 1000000007
long long qpow(long long a,long long m)//快速幂
{
long long ans=,k=a;
while(m)
{
if(m&)
ans=(ans*k)%M;
k=(k*k)%M;
m>>=;
}
return ans;
}
int main()
{
long long n,m,ans;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
ans=;
for(int i=; i<=n; i++)
ans+=qpow(i,m)%M;//这里mod一下
printf("%lld\n",ans%M);//这里mod一下
}
return ;
}

  

【CSU 1556】Pseudoprime numbers的更多相关文章

  1. 【POJ - 3641】Pseudoprime numbers (快速幂)

    Pseudoprime numbers Descriptions 费马定理指出,对于任意的素数 p 和任意的整数 a > 1,满足 ap = a (mod p) .也就是说,a的 p 次幂除以  ...

  2. 【HDU 4722】 Good Numbers

    [题目链接] 点击打开链接 [算法] f[i][j]表示第i位,数位和对10取模余j的数的个数 状态转移,计算答案都比较简单,笔者不再赘述 [代码] #include<bits/stdc++.h ...

  3. 【Codeforces 1036C】Classy Numbers

    [链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...

  4. 【Codeforces 300C】Beautiful Numbers

    [链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...

  5. 【LightOJ - 1205】Palindromic Numbers

    [链接]https://cn.vjudge.net/problem/LightOJ-1205 [题意] 求出L..R范围内的回文个数 [题解] 数位DP; 先求出1..x里面的回文串个数.则做一下前缀 ...

  6. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

  7. 【UVA - 136】Ugly Numbers(set)

    Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  8. 【CSU 1079】树上的查询

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1079 现有一棵有N个顶点的树,顶点的标号分别为1, 2, …, N.对于每个形如a b k的询问, ...

  9. 【CSU 1803】2016

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803 Solution: 考虑两个数x,y乘积%2016=0 x×y≡0(MOD 2016) x= ...

随机推荐

  1. codeforces 709B B. Checkpoints(水题)

    题目链接: B. Checkpoints 题意: 给了n个点,现在给一个起点,问最少访问n-1个点的最小行走距离是多少; 思路: 分情况讨论就好了; AC代码: #include <iostre ...

  2. HDU 1251 统计难题

    字典树又一基本题 代码: #include <iostream> #include <cstdio> #include <cstring> #include < ...

  3. POJ 2891 Strange Way to Express Integers【扩展欧几里德】【模线性方程组】

    求解方程组 X%m1=r1 X%m2=r2 .... X%mn=rn 首先看下两个式子的情况 X%m1=r1 X%m2=r2 联立可得 m1*x+m2*y=r2-r1 用ex_gcd求得一个特解x' ...

  4. 安卓内存不足(删除data/dalvik-cache目录)

    alvik-cache alvik-cache名词解释: 在系统data/dalvik-cache文件夹里有很多安装卸载文件(优化过的字节码),这些文件是当你安装好一个应用程序后,系统会自动生成的一个 ...

  5. Android优化——UI优化(二) 使用include标签复用布局

    使用include标签复用布局 - 1.include标签的作用 假如说我下图的这个布局在很多界面都用到了,我该怎么办?每个页面都写一遍的话,代码太冗余,并且维护难度加大. <LinearLay ...

  6. 【C#】【Thread】ManualResetEvent和AutoResetEvent区别

    ManualResetEvent和AutoResetEvent主要用于线程之间同步问题. 主要使用方法有Set();Reset();WaitOne(); Set():将事件状态设置为终止状态,允许一个 ...

  7. [转]curl_multi 实现准多进程发请求

    FROM : http://blog.sina.com.cn/s/blog_515b90d00100jtnv.html curl_multi函数族:curl_multi_closecurl_multi ...

  8. [转]World Wind Java开发之五——读取本地shp文件

    World Wind Java 使用IconLayer图层类表现点和多点数据,使用RenderableLayer图层表现线和面数据,一个图层只能对应一组shape文件.World Wind Java首 ...

  9. JS 之高级函数

    作用域安全的构造函数 当使用new调用构造函数时,构造函数内部this对象会指向新创建的对象实例.如果不使用new,直接调用的话,则this对象会映射到window对象上.所以需要判断下. eg: f ...

  10. 2015年新版C#从入门到精通(第2版)视频教学录像【无水印版】

    <c#从入门到精通(第2版)>以零基础讲解为宗旨,用实例引导读者学习,深入浅出地介绍了c#的相关知识和实战技能.<c#从入门到精通(第2版)>第1篇[c#语言基础]主要讲解c# ...