結果

問題 No.1259 スイッチ
コンテスト
ユーザー H3PO4
提出日時 2022-06-08 08:40:20
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 75 ms / 2,000 ms
+ 735µs
コード長 700 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 869 ms
コンパイル使用メモリ 96,040 KB
実行使用メモリ 90,808 KB
最終ジャッジ日時 2026-09-01 10:47:09
合計ジャッジ時間 8,324 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

MOD = 10 ** 9 + 7

modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)


def solve(N, K, M):
    if M == 1:
        return calc_1(N, K)
    else:
        return (pow(N, N, MOD) - calc_1(N, K)) * modinv(N - 1) % MOD


def calc_1(N, K):
    res = 0
    perm_tmp = 1
    pow_table = create_pow_table(N)
    for i in range(1, N + 1):
        if not K % i:
            res += perm_tmp * pow_table[N - i]
        perm_tmp *= N - i
        perm_tmp %= MOD
    res %= MOD
    return res


def create_pow_table(length: int) -> list:
    pow_table = [1] * length
    for i in range(1, length):
        pow_table[i] = pow_table[i - 1] * length % MOD
    return pow_table


print(solve(*map(int, input().split())))
0