結果

問題 No.673 カブトムシ
ユーザー ts_ts_
提出日時 2018-04-15 05:32:03
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 943 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 144,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 18:17:18
合計ジャッジ時間 2,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
ll modpow(ll x,ll n,ll mod){
    ll res=1;
    while(n>0){if(n&1ll) res=res*x%mod;x=x*x%mod;n>>=1;}
    return res;
}
ll exgcd(ll a,ll b,ll& x,ll& y){
    ll d=a;
    if(b!=0){
        d=exgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else{
        x=1;y=0;
    }
    return d;
}
ll mod_inverse(ll a,ll m){
    ll x,y;
    exgcd(a,m,x,y);
    return (m+x%m)%m;
}
int main(){
    ll b,c,d;
    cin>>b>>c>>d;
    if(d==1){
        cout<<b%mod*c%mod<<endl;
        return 0;
    }
    if(c==1){
        b%=mod,d%=mod;
        cout<<b*d%mod<<endl;
        return 0;
    }
    b%=mod,c%=mod;
    ll cn=modpow(c,d,mod);
    ll ans=c*((1-cn)+mod)%mod*mod_inverse((1-c)+mod,mod)%mod*b%mod;
    cout<<ans%mod<<endl;
    return 0;
}
0