結果
問題 |
No.1259 スイッチ
|
ユーザー |
![]() |
提出日時 | 2020-08-18 22:54:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 1,998 ms |
コンパイル使用メモリ | 168,576 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-20 18:33:04 |
合計ジャッジ時間 | 3,714 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 61 |
ソースコード
#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; ll inf=1e18; assert(1<=N&&N<=max&&1<=M&&M<=max&&1<=K&&K<=inf&&M<=N); 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; } }