結果
問題 | No.1259 スイッチ |
ユーザー |
![]() |
提出日時 | 2023-04-03 19:26:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 1,092 bytes |
コンパイル時間 | 1,686 ms |
コンパイル使用メモリ | 170,252 KB |
実行使用メモリ | 26,668 KB |
最終ジャッジ日時 | 2024-09-25 01:14:13 |
合計ジャッジ時間 | 7,231 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 61 |
ソースコード
#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; } }