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

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

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 354   Solved: 51

Submit Web 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 % mod;
        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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值