結果
問題 |
No.1259 スイッチ
|
ユーザー |
![]() |
提出日時 | 2020-08-18 22:30:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 739 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 166,972 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-20 18:32:39 |
合計ジャッジ時間 | 10,209 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 RE * 51 |
ソースコード
#include<bits/stdc++.h> using std::cin; using std::cout; using std::endl; using ll=long long; const ll mod=1e9+7; ll modpow(ll X,ll Y){ ll ret=1; while(Y){ if(Y%2) ret=ret*X%mod; X=X*X%mod; Y/=2; } return ret; } int main(){ ll N,M,K; cin>>N>>K>>M; ll max=1e6; assert(1<=N&&N<=max&&1<=M&&M<=max&&1<=K&&K<=max); ll sum=1,ans=0; for(int i=1;i<=N;i++){ if(K%i==0){ ans+=sum*modpow(N,N-i)%mod; ans%=mod; } sum*=(N-i); sum%=mod; } if(M==1){ cout<<ans<<endl; } else{ ans=modpow(N,N)-ans; if(ans<0) ans+=mod; ans*=modpow(N-1,mod-2); ans%=mod; cout<<ans<<endl; } }