結果

問題 No.1259 スイッチ
ユーザー beetbeet
提出日時 2020-10-16 21:49:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 3,509 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 203,428 KB
実行使用メモリ 26,628 KB
最終ジャッジ日時 2023-09-28 02:49:33
合計ジャッジ時間 5,628 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
26,468 KB
testcase_01 AC 27 ms
26,484 KB
testcase_02 AC 28 ms
26,544 KB
testcase_03 AC 27 ms
26,320 KB
testcase_04 AC 24 ms
26,420 KB
testcase_05 AC 28 ms
26,428 KB
testcase_06 AC 27 ms
26,504 KB
testcase_07 AC 28 ms
26,324 KB
testcase_08 AC 26 ms
26,400 KB
testcase_09 AC 27 ms
26,400 KB
testcase_10 AC 32 ms
26,296 KB
testcase_11 AC 36 ms
26,364 KB
testcase_12 AC 34 ms
26,500 KB
testcase_13 AC 30 ms
26,280 KB
testcase_14 AC 30 ms
26,412 KB
testcase_15 AC 30 ms
26,612 KB
testcase_16 AC 33 ms
26,296 KB
testcase_17 AC 32 ms
26,340 KB
testcase_18 AC 34 ms
26,420 KB
testcase_19 AC 36 ms
26,548 KB
testcase_20 AC 37 ms
26,436 KB
testcase_21 AC 35 ms
26,428 KB
testcase_22 AC 29 ms
26,424 KB
testcase_23 AC 34 ms
26,292 KB
testcase_24 AC 32 ms
26,324 KB
testcase_25 AC 32 ms
26,492 KB
testcase_26 AC 36 ms
26,484 KB
testcase_27 AC 35 ms
26,384 KB
testcase_28 AC 33 ms
26,476 KB
testcase_29 AC 35 ms
26,400 KB
testcase_30 AC 31 ms
26,292 KB
testcase_31 AC 34 ms
26,460 KB
testcase_32 AC 29 ms
26,360 KB
testcase_33 AC 37 ms
26,348 KB
testcase_34 AC 32 ms
26,416 KB
testcase_35 AC 33 ms
26,544 KB
testcase_36 AC 31 ms
26,416 KB
testcase_37 AC 33 ms
26,628 KB
testcase_38 AC 33 ms
26,512 KB
testcase_39 AC 36 ms
26,332 KB
testcase_40 AC 35 ms
26,280 KB
testcase_41 AC 32 ms
26,420 KB
testcase_42 AC 35 ms
26,388 KB
testcase_43 AC 31 ms
26,432 KB
testcase_44 AC 34 ms
26,480 KB
testcase_45 AC 34 ms
26,416 KB
testcase_46 AC 32 ms
26,404 KB
testcase_47 AC 37 ms
26,472 KB
testcase_48 AC 30 ms
26,276 KB
testcase_49 AC 36 ms
26,420 KB
testcase_50 AC 31 ms
26,364 KB
testcase_51 AC 30 ms
26,412 KB
testcase_52 AC 34 ms
26,328 KB
testcase_53 AC 31 ms
26,428 KB
testcase_54 AC 35 ms
26,496 KB
testcase_55 AC 30 ms
26,440 KB
testcase_56 AC 32 ms
26,420 KB
testcase_57 AC 34 ms
26,428 KB
testcase_58 AC 32 ms
26,296 KB
testcase_59 AC 33 ms
26,360 KB
testcase_60 AC 37 ms
26,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,Int k){
    Mint num(1),dom(1);
    for(Int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename M_>
class Enumeration{
  using M = M_;
protected:
  static vector<M> fact,finv,invs;
public:
  static void init(Int n){
    n=min<decltype(M::mod)>(n,M::mod-1);

    Int m=fact.size();
    if(n<m) return;

    fact.resize(n+1,1);
    finv.resize(n+1,1);
    invs.resize(n+1,1);

    if(m==0) m=1;
    for(Int i=m;i<=n;i++) fact[i]=fact[i-1]*M(i);
    finv[n]=M(1)/fact[n];
    for(Int i=n;i>=m;i--) finv[i-1]=finv[i]*M(i);
    for(Int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1];
  }

  static M Fact(Int n){
    init(n);
    return fact[n];
  }
  static M Finv(Int n){
    init(n);
    return finv[n];
  }
  static M Invs(Int n){
    init(n);
    return invs[n];
  }

  static M C(Int n,Int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k]*finv[k];
  }

  static M P(Int n,Int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k];
  }

  // put n identical balls into k distinct boxes
  static M H(Int n,Int k){
    if(n<0||k<0) return M(0);
    if(!n&&!k) return M(1);
    init(n+k);
    return C(n+k-1,n);
  }
};
template<typename M>
vector<M> Enumeration<M>::fact=vector<M>();
template<typename M>
vector<M> Enumeration<M>::finv=vector<M>();
template<typename M>
vector<M> Enumeration<M>::invs=vector<M>();

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using M = Mint<Int>;
  using E = Enumeration<M>;
  E::init(1e6+10);

  Int n,k,m;
  cin>>n>>k>>m;

  M ans{0};
  for(Int l=1;l<=n;l++)
    if(k%l==0) ans+=E::C(n-1,l-1)*E::Fact(l-1)*M(n).pow(n-l);

  if(m!=1) ans=(M(n).pow(n)-ans)/M(n-1);
  cout<<ans<<newl;
  return 0;
}
0