結果
問題 | No.1259 スイッチ |
ユーザー | rnano |
提出日時 | 2023-04-04 00:32:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 3,275 bytes |
コンパイル時間 | 1,683 ms |
コンパイル使用メモリ | 170,584 KB |
実行使用メモリ | 26,880 KB |
最終ジャッジ日時 | 2024-09-25 04:36:01 |
合計ジャッジ時間 | 5,300 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
26,880 KB |
testcase_01 | AC | 24 ms
26,752 KB |
testcase_02 | AC | 24 ms
26,820 KB |
testcase_03 | AC | 23 ms
26,880 KB |
testcase_04 | AC | 24 ms
26,880 KB |
testcase_05 | AC | 24 ms
26,876 KB |
testcase_06 | AC | 22 ms
26,752 KB |
testcase_07 | AC | 23 ms
26,880 KB |
testcase_08 | AC | 24 ms
26,752 KB |
testcase_09 | AC | 23 ms
26,764 KB |
testcase_10 | AC | 31 ms
26,880 KB |
testcase_11 | AC | 32 ms
26,880 KB |
testcase_12 | AC | 30 ms
26,752 KB |
testcase_13 | AC | 27 ms
26,752 KB |
testcase_14 | AC | 29 ms
26,812 KB |
testcase_15 | AC | 28 ms
26,752 KB |
testcase_16 | AC | 44 ms
26,752 KB |
testcase_17 | AC | 39 ms
26,876 KB |
testcase_18 | AC | 33 ms
26,880 KB |
testcase_19 | AC | 34 ms
26,752 KB |
testcase_20 | AC | 30 ms
26,880 KB |
testcase_21 | AC | 33 ms
26,764 KB |
testcase_22 | AC | 26 ms
26,772 KB |
testcase_23 | AC | 31 ms
26,752 KB |
testcase_24 | AC | 30 ms
26,880 KB |
testcase_25 | AC | 30 ms
26,752 KB |
testcase_26 | AC | 33 ms
26,752 KB |
testcase_27 | AC | 32 ms
26,752 KB |
testcase_28 | AC | 29 ms
26,796 KB |
testcase_29 | AC | 32 ms
26,880 KB |
testcase_30 | AC | 30 ms
26,880 KB |
testcase_31 | AC | 31 ms
26,752 KB |
testcase_32 | AC | 27 ms
26,880 KB |
testcase_33 | AC | 32 ms
26,760 KB |
testcase_34 | AC | 30 ms
26,752 KB |
testcase_35 | AC | 30 ms
26,784 KB |
testcase_36 | AC | 31 ms
26,752 KB |
testcase_37 | AC | 30 ms
26,752 KB |
testcase_38 | AC | 31 ms
26,680 KB |
testcase_39 | AC | 33 ms
26,880 KB |
testcase_40 | AC | 33 ms
26,752 KB |
testcase_41 | AC | 33 ms
26,848 KB |
testcase_42 | AC | 34 ms
26,812 KB |
testcase_43 | AC | 30 ms
26,828 KB |
testcase_44 | AC | 34 ms
26,880 KB |
testcase_45 | AC | 34 ms
26,752 KB |
testcase_46 | AC | 28 ms
26,752 KB |
testcase_47 | AC | 33 ms
26,880 KB |
testcase_48 | AC | 29 ms
26,728 KB |
testcase_49 | AC | 34 ms
26,760 KB |
testcase_50 | AC | 29 ms
26,868 KB |
testcase_51 | AC | 26 ms
26,780 KB |
testcase_52 | AC | 34 ms
26,880 KB |
testcase_53 | AC | 29 ms
26,752 KB |
testcase_54 | AC | 35 ms
26,880 KB |
testcase_55 | AC | 27 ms
26,880 KB |
testcase_56 | AC | 27 ms
26,880 KB |
testcase_57 | AC | 32 ms
26,796 KB |
testcase_58 | AC | 29 ms
26,880 KB |
testcase_59 | AC | 33 ms
26,752 KB |
testcase_60 | AC | 34 ms
26,880 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i) #define Rep(i,a,b) for (int i = a; i < b; ++i) #define rRep(i,a,b) for (int i = a; i > b; --i) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define Bit(x,i) (((x)>>(i))&1) using ll = long long; using vi = vector<int>; using vll = vector<long long>; using vvi = vector<vi>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct settings{settings(){ios_base::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(15);};}settingss; const double PI = acos(-1); const int INF = 1001001001; const ll LINF = 1001001001001001001LL; const int mod = 1000000007; class modint { long long x; public: modint(long long x=0) : x((x%mod+mod)%mod) {} modint operator-() const { return modint(-x); } modint& operator+=(const modint& a) { if ((x += a.x) >= mod) x -= mod; return *this; } modint& operator-=(const modint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } modint& operator*=(const modint& a) { (x *= a.x) %= mod; return *this; } modint operator+(const modint& a) const { modint res(*this); return res+=a; } modint operator-(const modint& a) const { modint res(*this); return res-=a; } modint operator*(const modint& a) const { modint res(*this); return res*=a; } modint pow(ll t) const { if (!t) return 1; modint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } modint inv() const { return pow(mod-2); } modint& operator/=(const modint& a) { return (*this) *= a.inv(); } modint operator/(const modint& a) const { modint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; } }; const int MAX = 1000010; long long fac[MAX], finv[MAX], inv[MAX]; void NCKinit() { 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; } } long long NCK(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 powmod(ll n, ll p, ll m) { if(p == 0) return 1; ll res = powmod(n, p/2, m); n %= m; if(p%2 == 0) return (res*res) % m; return (((res*res) % m)*n) % m; } int main() { ll N, K, M; cin >> N >> K >> M; if(N == 1) { cout << 1 << endl; return 0; } NCKinit(); modint ans = 0; Rep(i, 1, N+1) { if(K%i != 0) continue; modint tmp = fac[N-1] * finv[N-i]; tmp *= powmod(N, N-i, mod); ans += tmp; } if(M == 1) { cout << ans << endl; return 0; } // M != 1 modint aans = powmod(N, N, mod); aans -= ans; // 終点は2~NのN-1通りある状態 aans /= N-1; cout << aans << endl; }