Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CSU 1556】Pseudoprime numbers

【CSU 1556】Pseudoprime numbers

作者头像
饶文津
发布于 2020-05-31 15:37:22
发布于 2020-05-31 15:37:22
36000
代码可运行
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏
运行总次数:0
代码可运行

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
代码运行次数:0
运行
复制
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
4 1
5 1
4 2
5 2
4 3

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
10
15
30
55
100

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

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

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#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 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
POJ-3641:Pseudoprime numbers(快速幂)
Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as base-a pseudoprimes, have this property for some a. (And some, known as Carmichael Numbers, are base-a pseudoprimes for all a.)
ACM算法日常
2018/08/07
3800
【HDU 5399】Too Simple
Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.
饶文津
2020/06/02
2620
codeforce 272B Dima and Sequence
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
风骨散人Chiam
2020/10/28
3750
hoj 2275 Number sequence
Given a number sequence which has N element(s), please calculate the number of different collocation for three number Ai, Aj, Ak, which satisfy that Ai < Aj > Ak and i < j < k.
全栈程序员站长
2022/07/06
1710
【HDU 5363】Key Set(和为偶数的子集个数)
soda has a set $S$ with $n$ integers $\{1, 2, \dots, n\}$. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of $S$ are key set.
饶文津
2020/06/02
5030
数学--数论--HDU 4675 GCD of Sequence
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b
风骨散人Chiam
2020/11/06
3130
K - Wand FZU - 2282 【 组合数 + 错排 】
N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, numbered from 1 to n(Wand_i owned by wizard_i). After the meeting, n wizards will take a wand one by one in the order of 1 to n. A boring wizard decided to reorder the wands. He is wondering how many ways to reorder the wands so that at least k wizards can get his own wand.
Lokinli
2023/03/09
1760
HDU 4059 The Boss on Mars(容斥原理)
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2494    Accepted Submission(s): 775 Problem Description On Mars, there is a huge company called ACM (A huge Company on Mars), and
ShenduCC
2018/04/26
6000
「2017 Multi-University Training Contest 1」2017多校训练1
1001 Add More Zero(签到题) 题目链接 HDU6033 Add More Zero image.png #include <cstdio> #include <cmath> int cas,m; int main(){ while(~scanf("%d",&m)){ printf("Case #%d: %d\n",++cas,(int)(m*log(2)/log(10))); } return 0; } 1002 Balala Power!(贪心) 题目链接 HDU6034 Ba
饶文津
2020/06/02
3780
「2017 Multi-University Training Contest 1」2017多校训练1
AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or pr
Angel_Kitty
2018/04/09
6830
AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only one integer T, indicates the number of tasks.
风骨散人Chiam
2020/11/06
4240
HDU 2227 Find the nondecreasing subsequences(DP)
大家好,又见面了,我是全栈君。 Problem Description How many nondecreasing subsequences can you find in th
全栈程序员站长
2022/07/06
1450
Fantasy of a Summation (LightOJ - 1213)(快速幂+简单思维)
题解:根据题目给的程序,就是计算给的这个序列,进行k次到n的循环,每个数需要加的次数是k*n^(k-1),所以快速幂取模,算计一下就可以了。
Lokinli
2023/03/09
1560
CodeForces - 262B
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
风骨散人Chiam
2020/10/28
3520
Code Forces 149DColoring Brackets(区间DP)
 Coloring Brackets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you
ShenduCC
2018/04/26
7000
Code Forces 149DColoring Brackets(区间DP)
CF思维联系– Codeforces-990C Bracket Sequences Concatenation Problem(括号匹配+模拟)
ACM思维题训练集合 A bracket sequence is a string containing only characters “(” and “)”.
风骨散人Chiam
2020/10/29
3820
FZU 2098 刻苦的小芳(卡特兰数,动态规划)
Problem 2098 刻苦的小芳 Accept: 42 Submit: 70 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description 小芳是一个努力用功的好孩子。快高考了,她正在努力备战中。她要完成n份作业,然后把完成的作业堆成老高的一堆。为了保证学习的效率,她总是在一份作业写完后还会回过头去复习一下。因此她总是在写完几份作业就从已写完的作业堆中从上到下拿几本来复习,要知道如果不这么做的话把作业弄乱就麻烦了。
ShenduCC
2018/04/26
6230
hdu 5063 Operation the Sequence(Bestcoder Round #13)「建议收藏」
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 158 Accepted Submission(s): 74
全栈程序员站长
2022/07/08
1990
「2017 Multi-University Training Contest 2」2017多校训练2
给定数组a[1..n]和b[1..n],b[i]在[1~n]内。要得到a[n+1..2n],每次选b数组的一个,令a[i]为j=b[k]到i-1位置中最大的a[j]-j。求a[n+1..2n]总和最大值。
饶文津
2020/06/02
3640
「2017 Multi-University Training Contest 2」2017多校训练2
洛谷P1313 计算系数【快速幂+dp】
P1313 计算系数 题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数。 输入输出格式 输入格式: 输入文件名为factor.in。 共一行,包含5 个整数,分别为 a ,b ,k ,n ,m,每两个整数之间用一个空格隔开。 输出格式: 输出共1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果。 输入输出样例 输入样例#1: 复制 1 1 3 1 2 输出样例#1: 复制 3 说明 【数据范围】 对于30% 的数据,有 0 ≤k
Angel_Kitty
2018/04/08
5480
推荐阅读
相关推荐
POJ-3641:Pseudoprime numbers(快速幂)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验