結果

問題 No.1259 スイッチ
ユーザー nemutainemutai
提出日時 2023-04-03 19:26:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 5,748 ms
コンパイル使用メモリ 170,384 KB
実行使用メモリ 26,844 KB
最終ジャッジ日時 2023-10-25 05:49:40
合計ジャッジ時間 8,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 71 ms
17,344 KB
testcase_11 AC 119 ms
25,248 KB
testcase_12 AC 65 ms
16,612 KB
testcase_13 AC 36 ms
11,204 KB
testcase_14 AC 53 ms
14,572 KB
testcase_15 AC 35 ms
10,940 KB
testcase_16 AC 90 ms
21,424 KB
testcase_17 AC 50 ms
14,040 KB
testcase_18 AC 102 ms
23,996 KB
testcase_19 AC 105 ms
23,744 KB
testcase_20 AC 68 ms
17,608 KB
testcase_21 AC 119 ms
25,776 KB
testcase_22 AC 32 ms
10,216 KB
testcase_23 AC 103 ms
23,468 KB
testcase_24 AC 72 ms
18,392 KB
testcase_25 AC 70 ms
18,128 KB
testcase_26 AC 121 ms
26,040 KB
testcase_27 AC 93 ms
21,952 KB
testcase_28 AC 73 ms
18,128 KB
testcase_29 AC 95 ms
21,952 KB
testcase_30 AC 54 ms
14,832 KB
testcase_31 AC 82 ms
19,908 KB
testcase_32 AC 33 ms
10,480 KB
testcase_33 AC 121 ms
26,304 KB
testcase_34 AC 59 ms
15,820 KB
testcase_35 AC 87 ms
20,964 KB
testcase_36 AC 79 ms
19,380 KB
testcase_37 AC 73 ms
18,392 KB
testcase_38 AC 66 ms
17,336 KB
testcase_39 AC 114 ms
25,052 KB
testcase_40 AC 116 ms
25,512 KB
testcase_41 AC 89 ms
21,424 KB
testcase_42 AC 117 ms
25,776 KB
testcase_43 AC 62 ms
16,612 KB
testcase_44 AC 110 ms
24,788 KB
testcase_45 AC 115 ms
26,832 KB
testcase_46 AC 58 ms
16,084 KB
testcase_47 AC 117 ms
26,568 KB
testcase_48 AC 50 ms
14,308 KB
testcase_49 AC 110 ms
25,776 KB
testcase_50 AC 58 ms
15,820 KB
testcase_51 AC 31 ms
10,216 KB
testcase_52 AC 107 ms
25,248 KB
testcase_53 AC 43 ms
12,984 KB
testcase_54 AC 109 ms
25,052 KB
testcase_55 AC 32 ms
9,688 KB
testcase_56 AC 51 ms
14,304 KB
testcase_57 AC 97 ms
23,468 KB
testcase_58 AC 63 ms
17,072 KB
testcase_59 AC 84 ms
20,172 KB
testcase_60 AC 124 ms
26,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
ll mod=1e9+7;

vector<ll> fact,invfact,inv;

void init(ll N){
    fact.resize(N+5);
    inv.resize(N+5);
    invfact.resize(N+5);
    fact[0]=1;fact[1]=1;
    invfact[0]=1;invfact[1]=1;
    inv[0]=1;inv[1]=1;
    for(int i=2;i<N+3;i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        invfact[i] = invfact[i-1]*inv[i]%mod;
    }
}

ll nCk(ll n,ll x){
    return fact[n]*invfact[n-x]%mod*invfact[x]%mod;
}

ll powmod(ll x,ll n,ll m){
    ll res=1;
    while(n>0){
        if(n&1) res*=x;
        x*=x;
        res%=m;
        x%=m;
        n>>=1;
    }
    return res;
}


int main(){
    ll N,K,M;
    cin>>N>>K>>M;
    init(N);
    ll ans=0;
    for(int i=1;i<=min(K,N);i++){
        if(K%i==0){
            ans+=nCk(N-1,i-1)*fact[i-1]%mod*powmod(N,N-i,mod);
        }
        ans%=mod;
    }
    if(M==1) cout<<ans<<endl;
    else{
        cout<<(powmod(N,N,mod)-ans+mod)*inv[N-1]%mod<<endl;
    }
}
0