結果
| 問題 |
No.2474 Empty Quartz
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2023-07-22 03:39:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 1,525 bytes |
| コンパイル時間 | 316 ms |
| コンパイル使用メモリ | 82,528 KB |
| 実行使用メモリ | 92,292 KB |
| 最終ジャッジ日時 | 2024-06-11 22:48:47 |
| 合計ジャッジ時間 | 2,256 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
"""
Empty Quartz (7) 想定解
"""
import sys
from sys import stdin
mod = 998244353
from collections import deque
def modfac(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def modnCr(n,r):
if n < 0 or r < 0 or n < r:
return 0
return fac[n] * inv[n-r] * inv[r] % mod
fac,inv = modfac(200000,mod)
T = int(stdin.readline())
assert 1 <= T <= 10**5
ANS = []
for loop in range(T):
N,K = map(int,stdin.readline().split())
assert 1 <= N <= 10**5
assert 0 <= K <= N*(N+1)//2
# x^2 - (N+1)x + K = 0 を解く
in_root = (N+1)**2 - 4 * K
if in_root < 0:
ANS.append(0)
continue
# 10^6 > root の時、pythonでこの処理で大丈夫なことはチェック済(下部)
root = int(in_root**0.5)
if root**2 != in_root:
ANS.append(0)
continue
topa = (N+1) + root
topb = (N+1) - root
ans = 0
if topa % 2 == 0 and 1 <= topa // 2 <= N+1:
ans += modnCr(N,topa//2-1)
if topb % 2 == 0 and topa != topb and 1 <= topb <= N+1:
ans += modnCr(N,topb//2-1)
ANS.append(ans % mod)
print (*ANS,sep="\n")
"""
# 精度チェック用
for i in range(1,10**6):
x = i**2
y = int(x**0.5)
if y**2 != x:
print (x,y)
"""
SPD_9X2