結果

問題 No.1259 スイッチ
ユーザー tamatotamato
提出日時 2020-10-16 22:47:26
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,230 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,708 KB
実行使用メモリ 102,528 KB
最終ジャッジ日時 2023-09-28 04:34:43
合計ジャッジ時間 21,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
99,536 KB
testcase_01 AC 112 ms
99,700 KB
testcase_02 AC 110 ms
99,284 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 111 ms
99,652 KB
testcase_06 AC 115 ms
99,528 KB
testcase_07 AC 114 ms
99,324 KB
testcase_08 RE -
testcase_09 AC 111 ms
99,628 KB
testcase_10 AC 365 ms
99,552 KB
testcase_11 AC 520 ms
99,640 KB
testcase_12 AC 351 ms
99,700 KB
testcase_13 AC 252 ms
99,720 KB
testcase_14 AC 315 ms
99,928 KB
testcase_15 AC 242 ms
99,748 KB
testcase_16 AC 453 ms
99,644 KB
testcase_17 AC 304 ms
99,644 KB
testcase_18 AC 490 ms
99,640 KB
testcase_19 AC 492 ms
99,636 KB
testcase_20 AC 375 ms
99,668 KB
testcase_21 AC 538 ms
99,664 KB
testcase_22 AC 229 ms
99,656 KB
testcase_23 AC 490 ms
99,760 KB
testcase_24 AC 393 ms
99,748 KB
testcase_25 AC 381 ms
99,356 KB
testcase_26 AC 543 ms
99,992 KB
testcase_27 AC 455 ms
99,524 KB
testcase_28 AC 377 ms
99,348 KB
testcase_29 AC 448 ms
99,952 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 338 ms
99,752 KB
testcase_51 AC 233 ms
99,636 KB
testcase_52 AC 527 ms
99,764 KB
testcase_53 AC 292 ms
99,920 KB
testcase_54 AC 523 ms
99,704 KB
testcase_55 AC 225 ms
99,988 KB
testcase_56 AC 309 ms
99,524 KB
testcase_57 AC 497 ms
99,572 KB
testcase_58 AC 364 ms
100,028 KB
testcase_59 AC 437 ms
99,616 KB
testcase_60 AC 558 ms
99,524 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 - 2, c - 2) * pow(N, N - c, mod)) % mod) % mod
        print(ans)
        assert False
        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