結果

問題 No.2406 Difference of Coordinate Squared
ユーザー shogo314shogo314
提出日時 2023-08-04 22:15:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,269 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 77,596 KB
最終ジャッジ日時 2024-04-22 20:32:55
合計ジャッジ時間 3,773 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
16,640 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


class MathCount:
    def __init__(self):
        self.fac = [1]
        self.fac_ = [1]

    def factorial(self, x, y=True):
        if y:
            while x >= len(self.fac):
                self.fac.append(self.fac[-1]*len(self.fac) % MOD)
            return self.fac[x]
        else:
            while x >= len(self.fac_):
                self.fac_.append(
                    self.fac_[-1]*pow(len(self.fac_), MOD-2, MOD) % MOD)
            return self.fac_[x]

    def nCr(self, n, r):
        return self.factorial(n, True)*self.factorial(r, False)*self.factorial(n-r, False) % MOD

    def nPr(self, n, r):
        return self.factorial(n, True)*self.factorial(n-r, False) % MOD

    def nHr(self, n, r):
        return self.nCr(n+r-1, r)


MOD = 998244353
N, M = map(int, input().split())
mc = MathCount()
ans = 0
for x in range(N+1):
    if x**2 < M:
        continue
    y = math.isqrt(x**2-M)
    if x**2-y**2 != M:
        continue
    if (x+y+N) % 2 == 1:
        continue
    k = (N-x-y)//2
    for i in range(k+1):
        tmp = 1
        tmp *= mc.nCr(N, x+i)
        tmp%=MOD
        tmp *= mc.nCr(N-x-i, i)
        tmp%=MOD
        tmp *= mc.nCr(N-x-2*i, y+k-i)
        tmp%=MOD
        ans+=tmp
ans*=pow(4,-N+1,MOD)
ans%=MOD
print(ans)
0