結果

問題 No.1259 スイッチ
ユーザー H3PO4H3PO4
提出日時 2022-06-08 08:40:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 81,396 KB
実行使用メモリ 67,192 KB
最終ジャッジ日時 2023-10-21 03:59:57
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,368 KB
testcase_01 AC 38 ms
53,368 KB
testcase_02 AC 39 ms
53,368 KB
testcase_03 AC 39 ms
53,368 KB
testcase_04 AC 38 ms
53,368 KB
testcase_05 AC 40 ms
53,368 KB
testcase_06 AC 39 ms
53,368 KB
testcase_07 AC 38 ms
53,368 KB
testcase_08 AC 38 ms
53,368 KB
testcase_09 AC 38 ms
53,368 KB
testcase_10 AC 61 ms
64,064 KB
testcase_11 AC 69 ms
66,676 KB
testcase_12 AC 61 ms
63,824 KB
testcase_13 AC 54 ms
62,008 KB
testcase_14 AC 57 ms
63,128 KB
testcase_15 AC 53 ms
61,912 KB
testcase_16 AC 65 ms
65,404 KB
testcase_17 AC 56 ms
62,980 KB
testcase_18 AC 68 ms
66,224 KB
testcase_19 AC 69 ms
66,188 KB
testcase_20 AC 61 ms
64,132 KB
testcase_21 AC 69 ms
66,868 KB
testcase_22 AC 52 ms
61,628 KB
testcase_23 AC 68 ms
66,060 KB
testcase_24 AC 62 ms
64,416 KB
testcase_25 AC 60 ms
64,276 KB
testcase_26 AC 71 ms
66,980 KB
testcase_27 AC 66 ms
65,552 KB
testcase_28 AC 61 ms
64,296 KB
testcase_29 AC 66 ms
65,532 KB
testcase_30 AC 58 ms
63,172 KB
testcase_31 AC 64 ms
64,912 KB
testcase_32 AC 52 ms
61,712 KB
testcase_33 AC 71 ms
67,024 KB
testcase_34 AC 59 ms
63,488 KB
testcase_35 AC 64 ms
65,228 KB
testcase_36 AC 62 ms
64,744 KB
testcase_37 AC 62 ms
64,416 KB
testcase_38 AC 61 ms
64,012 KB
testcase_39 AC 70 ms
66,628 KB
testcase_40 AC 71 ms
66,732 KB
testcase_41 AC 65 ms
65,428 KB
testcase_42 AC 73 ms
66,876 KB
testcase_43 AC 59 ms
63,776 KB
testcase_44 AC 68 ms
66,508 KB
testcase_45 AC 70 ms
67,176 KB
testcase_46 AC 58 ms
63,580 KB
testcase_47 AC 70 ms
67,100 KB
testcase_48 AC 58 ms
63,048 KB
testcase_49 AC 71 ms
66,864 KB
testcase_50 AC 60 ms
63,568 KB
testcase_51 AC 53 ms
61,660 KB
testcase_52 AC 70 ms
66,676 KB
testcase_53 AC 56 ms
62,592 KB
testcase_54 AC 69 ms
66,612 KB
testcase_55 AC 51 ms
61,528 KB
testcase_56 AC 58 ms
63,020 KB
testcase_57 AC 68 ms
66,060 KB
testcase_58 AC 60 ms
63,940 KB
testcase_59 AC 63 ms
65,000 KB
testcase_60 AC 71 ms
67,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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