Problem E: GJJ的日常之沉迷数学
2017-08-24 10:54
253 查看
Problem E: GJJ的日常之沉迷数学
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 354 Solved: 51
SubmitWeb
Board
Description
GJJ每天都要膜拜一发数学大佬,因为GJJ的数学太差了。这不,GJJ又遇到难题了,他想求助WJJ,但是WJJ这几天忙于追妹子,哪有时间给他讲题, 于是GJJ求助于热爱ACM的你,Acmer们能帮帮他吗?问题是求: k^0 + k^1 +...+ k^(n) mod p (0 < k < 100, 0 <= n <= 10^9, p = 1000000007)例如:6^0 + 6^1 +...+ 6^(10) mod 1000000007 (其中k = 6, n = 10, p = 1000000007)
Input
输入测试数据有多组,每组输入两个整数k, nOutput
每组测试数据输出:Case #: 计算结果Sample Input
2 16 10Sample Output
Case 1: 3Case 2: 72559411HINT
#include<bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1000000007ll; LL q_mod(LL a, LL b) { LL ans = 1ll; while(b) { if(b&1) ans = ans * a % mod; a = a * a % mo b488 d; b >>= 1; } return ans; } int main() { // freopen("in.txt", "r", stdin); // freopen("o.txt", "w", stdout); int n, k, cnt = 0; LL a, b, x; while(~scanf("%d%d", &k, &n)) { if(k == 1) { printf("Case %d: %d\n", ++cnt, n+1); continue; } a = q_mod(k, n+1) - 1ll; b = k - 1ll; x = q_mod(b, mod-2ll); printf("Case %d: %lld\n", ++cnt, a*x%mod); } return 0; }
相关文章推荐
- zzuli 2180 GJJ的日常之沉迷数学【矩阵快速幂 || 逆元】
- 【ZZULIOJ 2180】GJJ的日常之沉迷数学 【逆元 or 矩阵快速幂】
- GJJ的日常之沉迷数学
- zzuli2180: GJJ的日常之沉迷数学
- zzuli 2180 GJJ的日常之沉迷数学(逆元)
- 2181: GJJ的日常之暴富梦(数学)
- ZZULIOJ【2181】GJJ的日常之暴富梦【思维】&&【数学】
- 【日常学习】【数学/哈希】康托展开
- GJJ的日常之再游戏
- 多校连萌-GJJ的日常之暴富梦
- 2181: GJJ的日常之暴富梦
- (多校联萌)-zzu-2175: GJJ的日常之再游戏
- 【ZZULIOJ】 2181 GJJ的日常之暴富梦
- 周六日常训练,背包dp,树形dp,简单dp以及很多数学?
- GJJ的日常之再游戏
- zzuli 2172 GJJ的日常之购物【dp+优先队列】
- 【暑期多校联萌 - A】 GJJ的日常之再游戏
- 【GJJ的日常之再游戏】(数组排序去重)
- GJJ的日常之再游戏
- 用数学方法,教你如何赌场防沉迷