結果

問題 No.1259 スイッチ
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-10-16 23:17:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 111,124 KB
最終ジャッジ日時 2023-09-28 05:18:04
合計ジャッジ時間 11,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
110,752 KB
testcase_01 AC 135 ms
110,832 KB
testcase_02 AC 135 ms
110,688 KB
testcase_03 AC 132 ms
110,904 KB
testcase_04 AC 131 ms
110,904 KB
testcase_05 AC 133 ms
110,716 KB
testcase_06 AC 136 ms
110,692 KB
testcase_07 AC 137 ms
110,804 KB
testcase_08 AC 136 ms
110,800 KB
testcase_09 AC 133 ms
110,660 KB
testcase_10 AC 143 ms
110,668 KB
testcase_11 AC 147 ms
110,912 KB
testcase_12 AC 141 ms
110,912 KB
testcase_13 AC 141 ms
110,736 KB
testcase_14 AC 140 ms
110,976 KB
testcase_15 AC 139 ms
111,124 KB
testcase_16 AC 148 ms
110,788 KB
testcase_17 AC 138 ms
110,828 KB
testcase_18 AC 148 ms
110,792 KB
testcase_19 AC 145 ms
110,832 KB
testcase_20 AC 144 ms
110,656 KB
testcase_21 AC 146 ms
110,796 KB
testcase_22 AC 138 ms
111,016 KB
testcase_23 AC 147 ms
110,796 KB
testcase_24 AC 144 ms
110,656 KB
testcase_25 AC 144 ms
110,832 KB
testcase_26 AC 149 ms
110,552 KB
testcase_27 AC 147 ms
110,656 KB
testcase_28 AC 140 ms
110,916 KB
testcase_29 AC 145 ms
110,668 KB
testcase_30 AC 142 ms
110,696 KB
testcase_31 AC 149 ms
110,796 KB
testcase_32 AC 141 ms
110,980 KB
testcase_33 AC 149 ms
110,664 KB
testcase_34 AC 143 ms
110,664 KB
testcase_35 AC 144 ms
111,124 KB
testcase_36 AC 145 ms
110,668 KB
testcase_37 AC 143 ms
110,828 KB
testcase_38 AC 143 ms
110,596 KB
testcase_39 AC 153 ms
110,596 KB
testcase_40 AC 147 ms
110,832 KB
testcase_41 AC 147 ms
110,824 KB
testcase_42 AC 149 ms
111,120 KB
testcase_43 AC 142 ms
111,120 KB
testcase_44 AC 147 ms
110,876 KB
testcase_45 AC 147 ms
110,552 KB
testcase_46 AC 140 ms
110,652 KB
testcase_47 AC 147 ms
110,916 KB
testcase_48 AC 142 ms
110,824 KB
testcase_49 AC 147 ms
110,792 KB
testcase_50 AC 140 ms
110,788 KB
testcase_51 AC 140 ms
110,660 KB
testcase_52 AC 150 ms
110,596 KB
testcase_53 AC 140 ms
110,872 KB
testcase_54 AC 152 ms
110,796 KB
testcase_55 AC 138 ms
110,976 KB
testcase_56 AC 143 ms
110,596 KB
testcase_57 AC 149 ms
110,976 KB
testcase_58 AC 143 ms
110,792 KB
testcase_59 AC 147 ms
110,788 KB
testcase_60 AC 146 ms
110,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
MOD = 10**9 + 7

def mul(a, b):
    return ((a % MOD) * (b % MOD)) % MOD

def div(a, b):
    return mul(a, pow(b, MOD-2, MOD))

def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = MOD, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= MOD
    return u

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
            frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
            fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci

frac, fraci = frac(1341398)
def cmb(a, b):
    if not a >= b >= 0:
            return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD
def make_divisors(n):
    divisors = []
    for i in range(1, N+1):
        if n % i == 0:
            divisors.append(i)
    return divisors

N, K, M = map(int, input().split())
ss = make_divisors(K)
#print(ss)
a = 0
for y in ss:
    a = (a+pow(N, N-y, MOD)*frac[y-1]*cmb(N-1, y-1))%MOD
if M==1:
    print(a)
else:
    print(div2((pow(N, N, MOD)-a)%MOD, N-1))
0