結果

問題 No.1259 スイッチ
ユーザー umezoumezo
提出日時 2020-10-17 00:12:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 200,464 KB
実行使用メモリ 61,092 KB
最終ジャッジ日時 2023-09-28 07:01:11
合計ジャッジ時間 8,556 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
60,712 KB
testcase_01 AC 66 ms
60,748 KB
testcase_02 AC 68 ms
60,780 KB
testcase_03 AC 67 ms
60,824 KB
testcase_04 AC 67 ms
61,016 KB
testcase_05 AC 70 ms
60,892 KB
testcase_06 AC 69 ms
60,892 KB
testcase_07 AC 66 ms
60,900 KB
testcase_08 AC 67 ms
60,800 KB
testcase_09 AC 68 ms
60,816 KB
testcase_10 AC 75 ms
60,844 KB
testcase_11 AC 78 ms
60,720 KB
testcase_12 AC 78 ms
60,788 KB
testcase_13 AC 75 ms
60,740 KB
testcase_14 AC 75 ms
60,792 KB
testcase_15 AC 74 ms
60,956 KB
testcase_16 AC 82 ms
60,736 KB
testcase_17 AC 76 ms
60,828 KB
testcase_18 AC 77 ms
60,836 KB
testcase_19 AC 80 ms
60,956 KB
testcase_20 AC 80 ms
60,956 KB
testcase_21 AC 79 ms
60,736 KB
testcase_22 AC 72 ms
60,840 KB
testcase_23 AC 82 ms
60,780 KB
testcase_24 AC 84 ms
60,820 KB
testcase_25 AC 77 ms
60,788 KB
testcase_26 AC 79 ms
60,780 KB
testcase_27 AC 77 ms
60,828 KB
testcase_28 AC 75 ms
61,092 KB
testcase_29 AC 76 ms
60,740 KB
testcase_30 AC 80 ms
60,748 KB
testcase_31 AC 77 ms
60,804 KB
testcase_32 AC 73 ms
60,740 KB
testcase_33 AC 83 ms
60,812 KB
testcase_34 AC 80 ms
60,892 KB
testcase_35 AC 76 ms
60,884 KB
testcase_36 AC 76 ms
60,836 KB
testcase_37 AC 79 ms
60,736 KB
testcase_38 AC 76 ms
60,832 KB
testcase_39 AC 79 ms
60,832 KB
testcase_40 AC 81 ms
60,744 KB
testcase_41 AC 80 ms
60,896 KB
testcase_42 AC 79 ms
60,960 KB
testcase_43 AC 74 ms
60,768 KB
testcase_44 AC 79 ms
60,740 KB
testcase_45 AC 78 ms
60,832 KB
testcase_46 AC 74 ms
61,036 KB
testcase_47 AC 83 ms
60,784 KB
testcase_48 AC 70 ms
60,956 KB
testcase_49 AC 77 ms
60,824 KB
testcase_50 AC 74 ms
60,832 KB
testcase_51 AC 71 ms
60,784 KB
testcase_52 AC 90 ms
60,964 KB
testcase_53 AC 76 ms
60,760 KB
testcase_54 AC 80 ms
60,740 KB
testcase_55 AC 72 ms
60,828 KB
testcase_56 AC 74 ms
60,812 KB
testcase_57 AC 78 ms
60,800 KB
testcase_58 AC 74 ms
60,788 KB
testcase_59 AC 80 ms
60,712 KB
testcase_60 AC 83 ms
60,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll MOD=1e9+7;
const int MAX = 2100000;

ll fac[MAX], finv[MAX], inv[MAX];
ll b[MAX];

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll modinv(ll a,ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m; 
  if(u<0) u+=m;
  return u;
}

void initb(){
  b[0]=1;
  b[1]=1;
  for(int i=2;i<1000100;i++){
    b[i]=b[i-1]*i%MOD;
  }
}

ll nCr(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x %MOD;
    x=x*x %MOD;
    n/=2;
  }
  return ans;
}

int main(){
  init();
  initb();
  
  ll n,k,m;
  cin>>n>>k>>m;
  
  ll ans=0;
  for(int i=1;i<=n;i++){
    if(k%i==0) ans=(ans+(nCr(n-1,i-1)*modpow(n,n-i)%MOD)*b[i-1]%MOD)%MOD;
  }
  if(m==1) cout<<ans<<endl;
  else cout<<(modpow(n,n)-ans+MOD)%MOD*modinv(n-1,MOD)%MOD<<endl;

  return 0;
}
0