結果

問題 No.2406 Difference of Coordinate Squared
ユーザー flygon
提出日時 2023-08-04 22:47:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,259 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 337,516 KB
最終ジャッジ日時 2024-10-14 20:53:24
合計ジャッジ時間 5,552 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 TLE * 1 -- * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,m = map(int,input().split())
s = set()
for i in range(n+1):
    s.add(i**2)
xy = []
for i in range(n+1):
    xx = i*i
    yy = xx-m
    if yy in s:
        xy.append([i, int(yy**0.5)])
mod = 998244353

# nCk
def com(n, mod):
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1]*i) % mod)
        inv.append((-inv[mod % i]*(mod//i)) % mod)
        factinv.append((factinv[-1]*inv[-1]) % mod)
    return fact, factinv
f,fi = com(n+10, mod)

ans = 0
for x,y in xy:

    for dx in range(n+1):
        dy = n-dx
        if dx < x or dy < y: continue
        if dx%2 != x%2 or dy%2 != y%2: continue
        a = x + (dx-x)//2
        b = (dx-x)//2
        c = y + (dy-y)//2
        d = (dy-y)//2

        tmp = f[n] * fi[a]%mod * fi[b]%mod * fi[c]%mod * fi[d] %mod
        if x != 0:
            tmp *= 2
            tmp %= mod
        if y != 0:
            tmp *= 2
            tmp %= mod
        ans += tmp
        ans %= mod
print(ans * pow(pow(4, n, mod), mod-2, mod) % mod)
0