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. Android优化——UI优化(一)优化布局层次

    优化布局层次 1.避免布局镶嵌过深(如下) <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  2. IDEA 滚动条跳动问题

    关掉有道词典的 “屏幕取词” 和 “划词翻译”

  3. php报错日志:PHP Deprecated:Automatically populating $HTTP_RAW_POST_DATA is deprecated

    前几天将线上php服务升级到5.6.x版本后,php-error.log报出错误:PHP Deprecated: Automatically populating $HTTP_RAW_POST_DAT ...

  4. 09Mybatis_入门程序——删除用户以及更新用户

    删除用户: 还是前面的的案例,别的都不改,就修改两处地方.1.user.xml文件以及2.Mybatis_first.java文件 user.xml文件代码修改如下: <?xml version ...

  5. ubuntu中启用ssh服务

    ssh程序分为有客户端程序openssh-client和服务端程序openssh-server.如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...

  6. 【转】【UML】使用Visual Studio 2010 Team System中的架构师工具(设计与建模)

    Lab 1: 应用程序建模 实验目标 这个实验的目的是展示如何在Visual Studio 2010旗舰版中进行应用程序建模.团队中的架构师会通过建模确定应用程序是否满足客户的需求. 你可以创建不同级 ...

  7. 【转】Bresenham快速画直线算法

    一.             算法原理简介: 算法原理的详细描述及部分实现可参考: http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresen ...

  8. 34-php基础:cookie

    <?php //1.创建cookie //创建cookie,如下设置,cookie的过期时间为会话结束时 setcookie("name","gaoxiong&qu ...

  9. [C#]動態叫用Web Service

    http://www.dotblogs.com.tw/jimmyyu/archive/2009/04/22/8139.aspx 摘要 Web Service對大家來說想必都不陌生,也大都了解Web S ...

  10. 面试准备(三) Java 异常类层次结构

    在Java中,异常分为受检查的异常,与运行时异常. 两者都在异常类层次结构中.这类容易出选择题 考试你是否掌握了异常类并清楚哪些异常类必须捕获 下面的图展示了Java异常类的继承关系. 图1 粉红色的 ...