結果

問題 No.1259 スイッチ
ユーザー tamatotamato
提出日時 2020-10-16 22:46:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 100,112 KB
最終ジャッジ日時 2023-09-28 04:31:54
合計ジャッジ時間 19,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
99,756 KB
testcase_01 AC 123 ms
99,612 KB
testcase_02 AC 123 ms
99,804 KB
testcase_03 WA -
testcase_04 AC 124 ms
99,892 KB
testcase_05 AC 121 ms
99,728 KB
testcase_06 AC 120 ms
99,624 KB
testcase_07 AC 119 ms
99,604 KB
testcase_08 WA -
testcase_09 AC 124 ms
100,012 KB
testcase_10 AC 395 ms
99,856 KB
testcase_11 AC 549 ms
99,924 KB
testcase_12 AC 377 ms
99,924 KB
testcase_13 AC 272 ms
99,880 KB
testcase_14 AC 334 ms
99,924 KB
testcase_15 AC 263 ms
99,816 KB
testcase_16 AC 473 ms
99,904 KB
testcase_17 AC 316 ms
99,884 KB
testcase_18 AC 528 ms
99,636 KB
testcase_19 AC 539 ms
99,652 KB
testcase_20 AC 414 ms
100,020 KB
testcase_21 AC 572 ms
99,808 KB
testcase_22 AC 256 ms
99,900 KB
testcase_23 AC 522 ms
99,832 KB
testcase_24 AC 416 ms
99,776 KB
testcase_25 AC 409 ms
99,772 KB
testcase_26 AC 575 ms
99,980 KB
testcase_27 AC 479 ms
99,812 KB
testcase_28 AC 407 ms
99,816 KB
testcase_29 AC 488 ms
100,000 KB
testcase_30 AC 128 ms
99,660 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 130 ms
99,820 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 127 ms
99,844 KB
testcase_49 WA -
testcase_50 AC 356 ms
99,864 KB
testcase_51 AC 249 ms
99,936 KB
testcase_52 AC 561 ms
99,788 KB
testcase_53 AC 303 ms
99,828 KB
testcase_54 AC 547 ms
99,820 KB
testcase_55 AC 240 ms
99,644 KB
testcase_56 AC 324 ms
99,932 KB
testcase_57 AC 514 ms
99,812 KB
testcase_58 AC 386 ms
99,868 KB
testcase_59 AC 446 ms
99,976 KB
testcase_60 AC 585 ms
99,636 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)
        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