CSU 1556 Jerry's trouble

题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556

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

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

Hint

Source

题意:

  看sample猜公式。QAQ

题解:

  公式是 1^m + 2^m + ···· + n^m。用快速幂解决。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <vector>
 7 #include <map>
 8 #include <set>
 9 #include <queue>
10 #include <sstream>
11 #include <algorithm>
12 using namespace std;
13 #define pb push_back
14 #define mp make_pair
15 #define ms(a, b)  memset((a), (b), sizeof(a))
16 //#define LOCAL
17 #define eps 0.0000001
18 #define LNF (1<<60)
19 typedef long long LL;
20 const int inf = 0x3f3f3f3f;
21 const int maxn = 100000+10;
22 const int mod = 1e9+7;
23
24 LL qpow(LL a, LL b)
25 {
26     LL ans = 1;
27     LL base = a;
28     while(b){
29         if(b&1)     ans = (ans * base)%mod;
30         b >>= 1;
31         base = (base * base)%mod;
32     }
33     return ans;
34 }
35 int main()
36 {
37 #ifdef LOCAL
38     freopen("input.txt", "r", stdin);
39 //      freopen("output.txt", "w", stdout);
40 #endif // LOCAL
41
42     int n,m;
43     while(~scanf("%d%d", &n, &m))
44     {
45         LL ans = 0;
46         for(int i = 1;i<=n;i++)
47         {
48             ans = (ans + qpow(i, m))%mod;
49         }
50         printf("%lld\n", ans);
51     }
52     return 0;
53 }

CSU 1556 Jerry's trouble

时间: 2024-10-13 23:35:11

CSU 1556 Jerry's trouble的相关文章

CSU - 1556 Jerry&#39;s trouble(快速幂取模)

[题目链接]:click here~~\ [题目大意]:计算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 <= m < 1000) [解题思路]: 快速幂取模 代码: #include<bits/stdc++.h> #define LL long long using namespace std; const LL mod=(LL)1e9+7; LL pow_mod(LL a,LL p,LL n) { i

csu 1556: Jerry&#39;s trouble(大数取模)

题意:求出1^m+2^m+...n^m 思路:直接套用模板 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<stack> #include<ctype.h> #define LL l

csu 1556: Jerry&#39;s trouble(快速幂)

1556: Jerry's trouble Time Limit: 10 Sec  Memory Limit: 256 MB Submit: 445  Solved: 190 [Submit][Status][Web Board] 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 an

CSU - 1556 Jerry&amp;#39;s trouble(高速幂取模)

[题目链接]:click here [题目大意]:计算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 <= m < 1000) [解题思路]:高速幂取模 代码: solution one: #include<bits/stdc++.h> #define LL long long using namespace std; const LL mod=(LL)1e9+7; LL pow_mod(LL a,LL p

csu 1556(快速幂)

1556: Jerry's trouble Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 787  Solved: 317[Submit][Status][Web Board] 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 answ

湖南多校对抗赛3.28 J - Jerry&#39;s trouble

Problem J: Jerry's trouble Time Limit: 10 Sec  Memory Limit: 256 MB Submit: 96  Solved: 46 [Submit][Status][Web Board] 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

Jerry的Fiori原创文章合集

我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks My Appointments My Leads My Notes Simulate Sales Pipeline Track Sales Pipeline 在这不到两年的开发工作里,我在使用SAP UI5的过程中遇到各种各样的问题,我都把它们一一记录了下来.还有一些问题来源于我的好奇心,比如看到

CSU 1804: 有向无环图(拓扑排序)

http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1804 题意:…… 思路:对于某条路径,在遍历到某个点的时候,之前遍历过的点都可以到达它,因此在这个时候对答案的贡献就是∑(a1 + a2 + a3 + ... + ai) * bv,其中a是之前遍历到的点,v是当前遍历的点. 这样想之后就很简单了.类似于前缀和,每次遍历到一个v点,就把a[u]加给a[v],然后像平时的拓扑排序做就行了. 1 #include <bits/stdc++.h>

CSU 1111: 三家人【有趣的思维题】

1111: 三家人 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 2241  Solved: 874 [Submit][Status][Web Board] Description 有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请问这笔钱如何分给A.B 二位太太较为恰当?A 应得多少元?90/(5+4)*5=$50