結果
問題 | No.1259 スイッチ |
ユーザー | carrot46 |
提出日時 | 2020-10-16 22:16:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 3,153 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 169,780 KB |
実行使用メモリ | 26,624 KB |
最終ジャッジ日時 | 2024-07-20 22:05:58 |
合計ジャッジ時間 | 5,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
26,496 KB |
testcase_01 | AC | 25 ms
26,624 KB |
testcase_02 | AC | 28 ms
26,496 KB |
testcase_03 | AC | 28 ms
26,496 KB |
testcase_04 | AC | 28 ms
26,624 KB |
testcase_05 | AC | 26 ms
26,496 KB |
testcase_06 | AC | 30 ms
26,624 KB |
testcase_07 | AC | 27 ms
26,624 KB |
testcase_08 | AC | 27 ms
26,496 KB |
testcase_09 | AC | 28 ms
26,624 KB |
testcase_10 | AC | 33 ms
26,496 KB |
testcase_11 | AC | 36 ms
26,496 KB |
testcase_12 | AC | 31 ms
26,496 KB |
testcase_13 | AC | 32 ms
26,496 KB |
testcase_14 | AC | 31 ms
26,496 KB |
testcase_15 | AC | 32 ms
26,624 KB |
testcase_16 | AC | 34 ms
26,624 KB |
testcase_17 | AC | 33 ms
26,624 KB |
testcase_18 | AC | 35 ms
26,624 KB |
testcase_19 | AC | 37 ms
26,496 KB |
testcase_20 | AC | 34 ms
26,624 KB |
testcase_21 | AC | 37 ms
26,624 KB |
testcase_22 | AC | 30 ms
26,496 KB |
testcase_23 | AC | 37 ms
26,624 KB |
testcase_24 | AC | 35 ms
26,496 KB |
testcase_25 | AC | 36 ms
26,624 KB |
testcase_26 | AC | 37 ms
26,496 KB |
testcase_27 | AC | 36 ms
26,496 KB |
testcase_28 | AC | 32 ms
26,624 KB |
testcase_29 | AC | 35 ms
26,624 KB |
testcase_30 | AC | 30 ms
26,624 KB |
testcase_31 | AC | 36 ms
26,624 KB |
testcase_32 | AC | 29 ms
26,496 KB |
testcase_33 | AC | 39 ms
26,624 KB |
testcase_34 | AC | 33 ms
26,496 KB |
testcase_35 | AC | 37 ms
26,496 KB |
testcase_36 | AC | 34 ms
26,624 KB |
testcase_37 | AC | 35 ms
26,496 KB |
testcase_38 | AC | 33 ms
26,624 KB |
testcase_39 | AC | 38 ms
26,624 KB |
testcase_40 | AC | 36 ms
26,624 KB |
testcase_41 | AC | 36 ms
26,624 KB |
testcase_42 | AC | 36 ms
26,624 KB |
testcase_43 | AC | 34 ms
26,496 KB |
testcase_44 | AC | 36 ms
26,624 KB |
testcase_45 | AC | 37 ms
26,496 KB |
testcase_46 | AC | 33 ms
26,624 KB |
testcase_47 | AC | 39 ms
26,624 KB |
testcase_48 | AC | 34 ms
26,624 KB |
testcase_49 | AC | 36 ms
26,624 KB |
testcase_50 | AC | 34 ms
26,624 KB |
testcase_51 | AC | 30 ms
26,624 KB |
testcase_52 | AC | 37 ms
26,624 KB |
testcase_53 | AC | 31 ms
26,624 KB |
testcase_54 | AC | 37 ms
26,624 KB |
testcase_55 | AC | 30 ms
26,624 KB |
testcase_56 | AC | 32 ms
26,496 KB |
testcase_57 | AC | 37 ms
26,496 KB |
testcase_58 | AC | 34 ms
26,624 KB |
testcase_59 | AC | 33 ms
26,624 KB |
testcase_60 | AC | 36 ms
26,496 KB |
ソースコード
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; typedef pair<ll, ll> P; const ll INF = (1LL<<48); template <unsigned long long mod > class modint{ public: ll x; constexpr modint(){x = 0;} constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){} constexpr modint set_raw(ll _x){ //_x in [0, mod) x = _x; return *this; } constexpr modint operator-(){ return x == 0 ? 0 : mod - x; } constexpr modint& operator+=(const modint& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr modint operator+(const modint& a) const{ return modint(*this) += a; } constexpr modint& operator-=(const modint& a){ if((x -= a.x) < 0) x += mod; return *this; } constexpr modint operator-(const modint& a) const{ return modint(*this) -= a; } constexpr modint& operator*=(const modint& a){ (x *= a.x)%=mod; return *this; } constexpr modint operator*(const modint& a) const{ return modint(*this) *= a; } constexpr modint pow(unsigned long long pw) const{ modint res(1), comp(*this); while(pw){ if(pw&1) res *= comp; comp *= comp; pw >>= 1; } return res; } //以下、modが素数のときのみ constexpr modint inv() const{ if(x == 2) return (mod + 1) >> 1; return modint(*this).pow(mod - 2); } constexpr modint& operator/=(const modint &a){ (x *= a.inv().x)%=mod; return *this; } constexpr modint operator/(const modint &a) const{ return modint(*this) /= a; } }; #define mod2 1000000007 using mint = modint<mod2>; ostream& operator<<(ostream& os, const mint& a){ os << a.x; return os; } using vm = vector<mint>; const ll MAX_N = ll(1e+6) + 10; vm fact(MAX_N, mint(1)), fact_inv(MAX_N, mint(1)), n_inv(MAX_N, mint(1)); void makefact(){ mint tmp; reps(i,2,MAX_N) fact[i] = fact[i-1] * tmp.set_raw(i); fact_inv[MAX_N - 1] = fact[MAX_N - 1].inv(); Rreps(i, MAX_N - 1, 1){ fact_inv[i] = fact_inv[i + 1] * tmp.set_raw(i + 1); n_inv[i + 1] = fact[i] * fact_inv[i + 1]; } } mint nCm(ll n, ll m){ return fact[n] * fact_inv[n-m] * fact_inv[m]; } mint nCm_inv(ll n, ll m){ return fact[n-m] * fact[m] * fact_inv[n]; } int main() { makefact(); cin>>N>>K>>M; mint one(0); reps(i, 1, N + 1){ if(K%i == 0){ one += fact[N - 1] * fact_inv[N - i] * mint(N).pow(N - i); } } if(M == 1){ cout<<one<<endl; }else{ (one = mint(N).pow(N) - one) *= n_inv[N - 1]; cout<<one<<endl; } }