結果
| 問題 |
No.1259 スイッチ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-08 08:40:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 69 ms / 2,000 ms |
| コード長 | 700 bytes |
| コンパイル時間 | 840 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 67,716 KB |
| 最終ジャッジ日時 | 2024-09-21 05:03:38 |
| 合計ジャッジ時間 | 6,084 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 61 |
ソースコード
MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)
def solve(N, K, M):
if M == 1:
return calc_1(N, K)
else:
return (pow(N, N, MOD) - calc_1(N, K)) * modinv(N - 1) % MOD
def calc_1(N, K):
res = 0
perm_tmp = 1
pow_table = create_pow_table(N)
for i in range(1, N + 1):
if not K % i:
res += perm_tmp * pow_table[N - i]
perm_tmp *= N - i
perm_tmp %= MOD
res %= MOD
return res
def create_pow_table(length: int) -> list:
pow_table = [1] * length
for i in range(1, length):
pow_table[i] = pow_table[i - 1] * length % MOD
return pow_table
print(solve(*map(int, input().split())))