結果

問題 No.1259 スイッチ
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-13 15:25:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 3,184 ms
コンパイル使用メモリ 199,648 KB
実行使用メモリ 23,600 KB
最終ジャッジ日時 2024-04-13 15:26:00
合計ジャッジ時間 7,700 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
20,036 KB
testcase_01 AC 28 ms
19,904 KB
testcase_02 AC 28 ms
19,908 KB
testcase_03 AC 28 ms
19,912 KB
testcase_04 AC 28 ms
19,908 KB
testcase_05 AC 28 ms
20,032 KB
testcase_06 AC 27 ms
19,784 KB
testcase_07 AC 27 ms
20,036 KB
testcase_08 AC 27 ms
20,036 KB
testcase_09 AC 28 ms
19,780 KB
testcase_10 AC 38 ms
21,832 KB
testcase_11 AC 43 ms
23,112 KB
testcase_12 AC 39 ms
21,832 KB
testcase_13 AC 34 ms
20,928 KB
testcase_14 AC 37 ms
21,444 KB
testcase_15 AC 34 ms
20,928 KB
testcase_16 AC 46 ms
22,596 KB
testcase_17 AC 37 ms
21,444 KB
testcase_18 AC 43 ms
22,980 KB
testcase_19 AC 43 ms
22,968 KB
testcase_20 AC 40 ms
22,080 KB
testcase_21 AC 46 ms
23,492 KB
testcase_22 AC 32 ms
20,808 KB
testcase_23 AC 45 ms
22,852 KB
testcase_24 AC 39 ms
22,212 KB
testcase_25 AC 39 ms
22,120 KB
testcase_26 AC 44 ms
23,384 KB
testcase_27 AC 42 ms
22,704 KB
testcase_28 AC 40 ms
22,084 KB
testcase_29 AC 41 ms
22,748 KB
testcase_30 AC 36 ms
21,576 KB
testcase_31 AC 40 ms
22,344 KB
testcase_32 AC 32 ms
20,800 KB
testcase_33 AC 45 ms
23,440 KB
testcase_34 AC 37 ms
21,696 KB
testcase_35 AC 42 ms
22,468 KB
testcase_36 AC 40 ms
22,260 KB
testcase_37 AC 41 ms
22,080 KB
testcase_38 AC 37 ms
21,956 KB
testcase_39 AC 45 ms
23,204 KB
testcase_40 AC 45 ms
23,156 KB
testcase_41 AC 41 ms
22,468 KB
testcase_42 AC 45 ms
23,236 KB
testcase_43 AC 39 ms
21,672 KB
testcase_44 AC 47 ms
23,148 KB
testcase_45 AC 48 ms
23,600 KB
testcase_46 AC 39 ms
21,704 KB
testcase_47 AC 45 ms
23,512 KB
testcase_48 AC 36 ms
21,440 KB
testcase_49 AC 44 ms
23,236 KB
testcase_50 AC 39 ms
21,704 KB
testcase_51 AC 33 ms
20,804 KB
testcase_52 AC 45 ms
23,256 KB
testcase_53 AC 36 ms
21,188 KB
testcase_54 AC 44 ms
23,212 KB
testcase_55 AC 34 ms
20,672 KB
testcase_56 AC 35 ms
21,448 KB
testcase_57 AC 42 ms
23,012 KB
testcase_58 AC 37 ms
21,868 KB
testcase_59 AC 40 ms
22,468 KB
testcase_60 AC 46 ms
23,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint1000000007;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

mint fac[1 << 21], inv[1 << 21];
void init() {
    fac[0] = 1;
    for (int i = 1; i < (1 << 21); i++) {
        fac[i] = fac[i - 1] * i;
    }
    inv[(1 << 21) - 1] = fac[(1 << 21) - 1].inv();
    for (int i = (1 << 21) - 2; i >= 0; i--) {
        inv[i] = inv[i + 1] * (i + 1);
    }
}
mint binom(int n, int k) { return fac[n] * inv[k] * inv[n - k]; }
mint perm(int n, int k) { return fac[n] * inv[n - k]; }
int main() {
    fast_io();
    init();
    int n, m;
    long long k;
    cin >> n >> k >> m;
    mint ans = 0;
    vector<mint> npow(n + 1);
    npow[0] = 1;
    for (int i = 1; i <= n; i++) {
        npow[i] = npow[i - 1] * n;
    }
    for (long long i = 1; i <= n; i++) {
        if (k % i == 0) {
            ans += perm(n - 1, i - 1) * npow[n - i];
        }
    }
    if (m != 1) {
        ans = (npow[n] - ans) / (n - 1);
    }
    cout << ans.val() << endl;
}
0