結果

問題 No.673 カブトムシ
ユーザー face4
提出日時 2020-04-10 18:03:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 63,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 07:09:07
合計ジャッジ時間 1,484 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;

// a^b mod p を計算する
ll modpow(ll a, ll b, ll p){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    ll b, c, d;
    cin >> b >> c >> d;

    if(c%mod == 1){
        cout << (b%mod)*(d%mod)%mod << endl;
        return 0;
    }

    ll f = (b%mod)*(c%mod)%mod;

    ll alpha = ((mod-(b%mod)*(c%mod)%mod)%mod) * modpow((c-1)%mod, mod-2, mod) % mod;

    ll ans = ((f-alpha+mod)%mod * modpow(c%mod, d-1, mod) % mod + alpha) % mod;

    cout << ans%mod << endl;

    return 0;
}
0