您的位置:首页 > 其它

Problem E: GJJ的日常之沉迷数学

2017-08-24 10:54 253 查看

Problem E: GJJ的日常之沉迷数学

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 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, n

Output

每组测试数据输出:Case #: 计算结果

Sample Input

2 16 10

Sample Output

Case 1: 3Case 2: 72559411

HINT

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: