結果
問題 | No.1259 スイッチ |
ユーザー |
|
提出日時 | 2020-11-29 16:07:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 3,420 bytes |
コンパイル時間 | 1,126 ms |
コンパイル使用メモリ | 102,948 KB |
実行使用メモリ | 10,944 KB |
最終ジャッジ日時 | 2023-10-11 02:28:16 |
合計ジャッジ時間 | 4,954 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 1 ms
4,352 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,352 KB |
testcase_07 | AC | 2 ms
4,352 KB |
testcase_08 | AC | 1 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 16 ms
7,844 KB |
testcase_11 | AC | 23 ms
10,604 KB |
testcase_12 | AC | 16 ms
7,520 KB |
testcase_13 | AC | 11 ms
5,736 KB |
testcase_14 | AC | 13 ms
6,720 KB |
testcase_15 | AC | 10 ms
5,628 KB |
testcase_16 | AC | 20 ms
8,984 KB |
testcase_17 | AC | 13 ms
6,860 KB |
testcase_18 | AC | 23 ms
9,776 KB |
testcase_19 | AC | 22 ms
9,820 KB |
testcase_20 | AC | 16 ms
7,784 KB |
testcase_21 | AC | 24 ms
10,688 KB |
testcase_22 | AC | 9 ms
5,152 KB |
testcase_23 | AC | 22 ms
9,828 KB |
testcase_24 | AC | 18 ms
8,004 KB |
testcase_25 | AC | 16 ms
8,120 KB |
testcase_26 | AC | 24 ms
10,612 KB |
testcase_27 | AC | 21 ms
9,244 KB |
testcase_28 | AC | 17 ms
8,056 KB |
testcase_29 | AC | 20 ms
9,312 KB |
testcase_30 | AC | 14 ms
6,852 KB |
testcase_31 | AC | 19 ms
8,640 KB |
testcase_32 | AC | 9 ms
5,540 KB |
testcase_33 | AC | 24 ms
10,700 KB |
testcase_34 | AC | 15 ms
7,328 KB |
testcase_35 | AC | 21 ms
8,800 KB |
testcase_36 | AC | 18 ms
8,452 KB |
testcase_37 | AC | 17 ms
8,040 KB |
testcase_38 | AC | 16 ms
7,796 KB |
testcase_39 | AC | 23 ms
10,284 KB |
testcase_40 | AC | 24 ms
10,368 KB |
testcase_41 | AC | 21 ms
9,172 KB |
testcase_42 | AC | 24 ms
10,688 KB |
testcase_43 | AC | 16 ms
7,464 KB |
testcase_44 | AC | 22 ms
10,552 KB |
testcase_45 | AC | 25 ms
10,888 KB |
testcase_46 | AC | 16 ms
7,260 KB |
testcase_47 | AC | 25 ms
10,944 KB |
testcase_48 | AC | 13 ms
7,044 KB |
testcase_49 | AC | 23 ms
10,504 KB |
testcase_50 | AC | 16 ms
7,336 KB |
testcase_51 | AC | 9 ms
5,544 KB |
testcase_52 | AC | 23 ms
10,428 KB |
testcase_53 | AC | 12 ms
6,148 KB |
testcase_54 | AC | 24 ms
10,360 KB |
testcase_55 | AC | 9 ms
5,216 KB |
testcase_56 | AC | 14 ms
6,724 KB |
testcase_57 | AC | 21 ms
9,820 KB |
testcase_58 | AC | 17 ms
7,528 KB |
testcase_59 | AC | 19 ms
8,532 KB |
testcase_60 | AC | 24 ms
10,808 KB |
ソースコード
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <u32 M> struct modint { u32 val; public: static modint raw(int v) { modint x; x.val = v; return x; } modint() : val(0) {} template <class T> modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = u32(x); } modint(bool v) { val = ((unsigned int)(v) % M); } modint& operator++() { val++; if (val == M) val = 0; return *this; } modint& operator--() { if (val == 0) val = M; val--; return *this; } modint operator++(int) { modint result = *this; ++*this; return result; } modint operator--(int) { modint result = *this; --*this; return result; } modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; } modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; } modint& operator*=(const modint& b) { u64 z = val; z *= b.val; val = (u32)(z % M); return *this; } modint& operator/=(const modint& b) { return *this = *this * b.inv(); } modint operator+() const { return *this; } modint operator-() const { return modint() - *this; } modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } modint inv() const { return pow(M-2); } friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; } friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; } friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; } friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; } friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; } friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; } }; using mint = modint<MOD>; class Factorial { vector<mint> facts, factinv; public: explicit Factorial(int n) : facts(n+1), factinv(n+1) { facts[0] = 1; for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1] * mint(i); factinv[n] = facts[n].inv(); for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * mint(i+1); } mint fact(int k) const { if(k >= 0) return facts[k]; else return factinv[-k]; } mint operator[](const int &k) const { if(k >= 0) return facts[k]; else return factinv[-k]; } mint C(int p, int q) const { if(q < 0 || p < q) return 0; return facts[p] * factinv[q] * factinv[p-q]; } mint P(int p, int q) const { if(q < 0 || p < q) return 0; return facts[p] * factinv[p-q]; } mint H(int p, int q) const { if(p < 0 || q < 0) return 0; return q == 0 ? 1 : C(p+q-1, q); } }; int main() { ll n, k, m; cin >> n >> k >> m; Factorial f(n); mint ans = 0; for (int i = 1; i <= n; ++i) { if(k%i == 0){ ans += mint(n).pow(n-i)*f.P(n-1, i-1); } } if(m == 1) cout << ans.val << "\n"; else cout << (mint(n-1).inv()*(mint(n).pow(n)-ans)).val << "\n"; return 0; }