結果
| 問題 | No.2406 Difference of Coordinate Squared |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-28 12:54:10 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,218 bytes |
| 記録 | |
| コンパイル時間 | 334 ms |
| コンパイル使用メモリ | 78,144 KB |
| 実行使用メモリ | 104,480 KB |
| 最終ジャッジ日時 | 2026-02-28 12:54:18 |
| 合計ジャッジ時間 | 8,285 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 WA * 8 |
ソースコード
## https://yukicoder.me/problems/no/2406
import math
MOD = 998244353
class CombinationCalculator:
"""
modを考慮したPermutation, Combinationを計算するためのクラス
"""
def __init__(self, size, mod):
self.mod = mod
self.factorial = [0] * (size + 1)
self.factorial[0] = 1
for i in range(1, size + 1):
self.factorial[i] = (i * self.factorial[i - 1]) % self.mod
self.inv_factorial = [0] * (size + 1)
self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod)
for i in reversed(range(size)):
self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod
def calc_combination(self, n, r):
if n < 0 or n < r or r < 0:
return 0
if r == 0 or n == r:
return 1
ans = self.inv_factorial[n - r] * self.inv_factorial[r]
ans %= self.mod
ans *= self.factorial[n]
ans %= self.mod
return ans
def calc_permutation(self, n, r):
if n < 0 or n < r:
return 0
ans = self.inv_factorial[n - r]
ans *= self.factorial[n]
ans %= self.mod
return ans
def main():
N, M = map(int, input().split())
combi = CombinationCalculator(2* N, MOD)
# 約数列挙する
m = abs(M)
sqrt_m = int(math.sqrt(m))
base_divisors = []
for p in range(1, sqrt_m + 1):
if m % p == 0:
q = m // p
base_divisors.append(p)
if q != p:
base_divisors.append(q)
divisors = []
for d in base_divisors:
divisors.append(d)
divisors.append(-d)
# 答えを求めていく
answer = 0
for p in divisors:
q = M // p
if (N + p) % 2 == 0 and (N + q) % 2 == 0:
xu = (N + p) // 2
xv = (N + q) // 2
ans = combi.calc_combination(N, xu) * combi.calc_combination(N, xv)
ans %= MOD
answer += ans
answer %= MOD
inv_4 = pow(4, MOD - 2, MOD)
answer *= pow(inv_4, N, MOD)
answer %= MOD
print(answer)
if __name__ == "__main__":
main()