結果

問題 No.1259 スイッチ
ユーザー mkawa2mkawa2
提出日時 2021-12-04 23:49:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 160,952 KB
最終ジャッジ日時 2023-09-21 13:01:25
合計ジャッジ時間 22,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
160,084 KB
testcase_01 AC 144 ms
159,988 KB
testcase_02 AC 145 ms
159,880 KB
testcase_03 AC 142 ms
160,476 KB
testcase_04 AC 142 ms
160,260 KB
testcase_05 AC 142 ms
160,040 KB
testcase_06 WA -
testcase_07 AC 140 ms
159,904 KB
testcase_08 AC 142 ms
159,920 KB
testcase_09 AC 141 ms
160,268 KB
testcase_10 AC 441 ms
160,412 KB
testcase_11 AC 608 ms
160,320 KB
testcase_12 AC 427 ms
160,168 KB
testcase_13 AC 310 ms
160,236 KB
testcase_14 AC 383 ms
160,592 KB
testcase_15 AC 305 ms
160,276 KB
testcase_16 AC 522 ms
160,316 KB
testcase_17 AC 376 ms
160,544 KB
testcase_18 AC 576 ms
160,704 KB
testcase_19 AC 575 ms
160,344 KB
testcase_20 AC 447 ms
160,432 KB
testcase_21 AC 633 ms
160,380 KB
testcase_22 AC 288 ms
160,452 KB
testcase_23 AC 563 ms
160,236 KB
testcase_24 AC 464 ms
159,992 KB
testcase_25 AC 454 ms
160,168 KB
testcase_26 AC 621 ms
160,280 KB
testcase_27 AC 532 ms
160,068 KB
testcase_28 AC 451 ms
160,096 KB
testcase_29 AC 530 ms
160,272 KB
testcase_30 AC 157 ms
160,476 KB
testcase_31 AC 152 ms
159,988 KB
testcase_32 AC 157 ms
160,328 KB
testcase_33 AC 160 ms
160,032 KB
testcase_34 AC 156 ms
160,072 KB
testcase_35 AC 157 ms
160,072 KB
testcase_36 AC 156 ms
160,268 KB
testcase_37 AC 156 ms
160,112 KB
testcase_38 AC 155 ms
160,068 KB
testcase_39 AC 155 ms
159,932 KB
testcase_40 AC 156 ms
160,704 KB
testcase_41 AC 158 ms
160,004 KB
testcase_42 AC 157 ms
160,164 KB
testcase_43 AC 157 ms
160,328 KB
testcase_44 AC 158 ms
159,948 KB
testcase_45 AC 157 ms
160,124 KB
testcase_46 AC 156 ms
160,056 KB
testcase_47 AC 156 ms
160,332 KB
testcase_48 AC 156 ms
160,060 KB
testcase_49 AC 156 ms
160,040 KB
testcase_50 AC 406 ms
160,480 KB
testcase_51 AC 288 ms
160,164 KB
testcase_52 AC 606 ms
160,600 KB
testcase_53 AC 345 ms
160,348 KB
testcase_54 AC 601 ms
160,536 KB
testcase_55 AC 279 ms
160,952 KB
testcase_56 AC 367 ms
160,168 KB
testcase_57 AC 561 ms
160,168 KB
testcase_58 AC 431 ms
160,376 KB
testcase_59 AC 495 ms
160,112 KB
testcase_60 AC 637 ms
160,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
md = 10**9+7
# md = 998244353

def nHr(hn, hr):
    return nCr(hn+hr-1, hr-1)

def nPr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_n-com_r]%md

def nCr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_r]%md*ifac[com_n-com_r]%md

# 準備
n_max = 1000005
fac = [1]
for i in range(1, n_max+1): fac.append(fac[-1]*i%md)
ifac = [1]*(n_max+1)
ifac[n_max] = pow(fac[n_max], md-2, md)
for i in range(n_max-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%md

def factors(a):
    res = []
    for f in range(1, min(a, 1000000)+1):
        if a%f == 0: res.append(f)
    return res

n, k, m = LI()
ff = set(factors(k))

if m == 1:
    ans = 0
    for a in ff:
        a -= 1
        ans += nPr(n-1, a)*pow(n, n-1-a, md)%md
        ans %= md
    print(ans)
    exit()

ans = nPr(n-1, k)

for a in range(1, min(k, n)):
    c = a if a+1 in ff else a+1
    ans += nPr(n-2, a-1)*c%md*pow(n, n-1-a, md)%md
    ans %= md

print(ans)
0