結果

問題 No.2474 Empty Quartz
ユーザー rlangevinrlangevin
提出日時 2023-12-22 08:55:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 80,468 KB
最終ジャッジ日時 2023-12-22 08:55:53
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,624 KB
testcase_01 AC 46 ms
62,624 KB
testcase_02 WA -
testcase_03 AC 99 ms
78,996 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353
n = 2*10**5+5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod

def f(N, k):
    ma = (N + 1)//2
    if k > (N + 1 - ma) * ma:
        return -1
    if k == 0:
        return 0
    yes = ma
    no = 0
    while yes - no != 1:
        mid = (yes + no)//2
        if k <= mid * (N + 1 - mid):
            yes = mid
        else:
            no = mid
    if k == yes * (N + 1 - yes):
        return yes
    else:
        return -1

T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    print(comb(N + int(N%2==0), f(N, K)))
0