結果
問題 | No.2474 Empty Quartz |
ユーザー |
👑 ![]() |
提出日時 | 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 sysfrom sys import stdinmod = 998244353from collections import dequedef modfac(n, MOD):f = 1factorials = [1]for m in range(1, n + 1):f *= mf %= MODfactorials.append(f)inv = pow(f, MOD - 2, MOD)invs = [1] * (n + 1)invs[n] = invfor m in range(n, 1, -1):inv *= minv %= MODinvs[m - 1] = invreturn factorials, invsdef modnCr(n,r):if n < 0 or r < 0 or n < r:return 0return fac[n] * inv[n-r] * inv[r] % modfac,inv = modfac(200000,mod)T = int(stdin.readline())assert 1 <= T <= 10**5ANS = []for loop in range(T):N,K = map(int,stdin.readline().split())assert 1 <= N <= 10**5assert 0 <= K <= N*(N+1)//2# x^2 - (N+1)x + K = 0 を解くin_root = (N+1)**2 - 4 * Kif 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)continuetopa = (N+1) + roottopb = (N+1) - rootans = 0if 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**2y = int(x**0.5)if y**2 != x:print (x,y)"""