結果
問題 | No.1259 スイッチ |
ユーザー |
![]() |
提出日時 | 2020-08-18 22:48:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 764 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 192,364 KB |
最終ジャッジ日時 | 2025-01-13 03:31:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 maxx=1e18; assert(1<=N&&N<=max&&1<=M&&M<=max&&1<=K&&K<=maxx&&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; } }