結果
| 問題 |
No.1259 スイッチ
|
| コンテスト | |
| ユーザー |
iomir
|
| 提出日時 | 2023-04-03 19:24:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,081 bytes |
| コンパイル時間 | 1,606 ms |
| コンパイル使用メモリ | 171,664 KB |
| 実行使用メモリ | 26,720 KB |
| 最終ジャッジ日時 | 2024-09-25 01:12:09 |
| 合計ジャッジ時間 | 7,258 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 46 WA * 15 |
ソースコード
#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<=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)*inv[N-1]%mod<<endl;
}
}
iomir