結果

問題 No.1259 スイッチ
ユーザー tamatotamato
提出日時 2020-10-16 22:48:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 100,064 KB
最終ジャッジ日時 2023-09-28 04:35:36
合計ジャッジ時間 18,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
99,528 KB
testcase_01 AC 118 ms
99,836 KB
testcase_02 AC 113 ms
99,728 KB
testcase_03 AC 112 ms
99,616 KB
testcase_04 AC 118 ms
99,728 KB
testcase_05 AC 117 ms
99,724 KB
testcase_06 AC 113 ms
99,452 KB
testcase_07 AC 116 ms
99,480 KB
testcase_08 AC 117 ms
99,724 KB
testcase_09 AC 118 ms
99,792 KB
testcase_10 AC 374 ms
99,740 KB
testcase_11 AC 530 ms
99,580 KB
testcase_12 AC 360 ms
99,800 KB
testcase_13 AC 252 ms
99,680 KB
testcase_14 AC 318 ms
99,784 KB
testcase_15 AC 249 ms
99,372 KB
testcase_16 AC 448 ms
99,692 KB
testcase_17 AC 306 ms
99,692 KB
testcase_18 AC 488 ms
99,496 KB
testcase_19 AC 495 ms
99,804 KB
testcase_20 AC 388 ms
99,756 KB
testcase_21 AC 545 ms
99,620 KB
testcase_22 AC 233 ms
99,624 KB
testcase_23 AC 491 ms
100,000 KB
testcase_24 AC 390 ms
99,756 KB
testcase_25 AC 377 ms
99,996 KB
testcase_26 AC 541 ms
99,544 KB
testcase_27 AC 466 ms
99,388 KB
testcase_28 AC 385 ms
99,744 KB
testcase_29 AC 454 ms
99,696 KB
testcase_30 AC 125 ms
99,736 KB
testcase_31 AC 126 ms
99,460 KB
testcase_32 AC 118 ms
99,744 KB
testcase_33 AC 132 ms
99,452 KB
testcase_34 AC 123 ms
99,468 KB
testcase_35 AC 128 ms
99,636 KB
testcase_36 AC 131 ms
99,480 KB
testcase_37 AC 125 ms
99,488 KB
testcase_38 AC 124 ms
99,460 KB
testcase_39 AC 126 ms
99,360 KB
testcase_40 AC 128 ms
99,600 KB
testcase_41 AC 126 ms
99,596 KB
testcase_42 AC 129 ms
99,724 KB
testcase_43 AC 126 ms
99,716 KB
testcase_44 AC 131 ms
99,752 KB
testcase_45 AC 130 ms
99,424 KB
testcase_46 AC 125 ms
99,452 KB
testcase_47 AC 132 ms
99,500 KB
testcase_48 AC 124 ms
99,592 KB
testcase_49 AC 130 ms
99,976 KB
testcase_50 AC 347 ms
100,064 KB
testcase_51 AC 233 ms
99,816 KB
testcase_52 AC 524 ms
99,880 KB
testcase_53 AC 277 ms
99,584 KB
testcase_54 AC 519 ms
99,736 KB
testcase_55 AC 227 ms
100,004 KB
testcase_56 AC 306 ms
99,736 KB
testcase_57 AC 478 ms
99,876 KB
testcase_58 AC 364 ms
99,688 KB
testcase_59 AC 422 ms
100,016 KB
testcase_60 AC 546 ms
99,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 10 ** 6 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    def P(n, r):
        return (fac[n] * finv[n - r])%mod

    N, K, M = map(int, input().split())
    if M == 1:
        ans = pow(N, N-1, mod)
        for c in range(2, N + 1):
            if K % c == 0:
                ans = (ans + (P(N - 1, c - 1) * pow(N, N - c, mod)) % mod) % mod
        print(ans)
        exit()
    ans = 0
    for c in range(2, N+1):
        ans = (ans + ((P(N - 2, c - 2) * c)%mod * pow(N, N - c, mod))%mod)%mod
        if K % c == 0:
            ans = (ans - (P(N - 2, c-2)* pow(N, N - c, mod))%mod)%mod
    print(ans)


if __name__ == '__main__':
    main()
0