結果

問題 No.2406 Difference of Coordinate Squared
ユーザー tassei903
提出日時 2023-08-04 22:25:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,735 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 102,784 KB
最終ジャッジ日時 2024-11-26 18:04:20
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
mod = 998244353
nn = 2*10**6 + 10
fact = [1] * nn
for i in range(nn - 1):
    fact[i + 1] = fact[i] * (i + 1) % mod
invfact = [1] * nn
invfact[nn - 1] = pow(fact[nn - 1], mod - 2, mod)
for i in range(nn - 1)[::-1]:
    invfact[i] = invfact[i + 1] * (i + 1) % mod
 
def binom(x, y):
    if x < 0 or y < 0 or x - y < 0:
        return 0
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod

n, m = na()

d = divisors(abs(m))
ans = 0
if m != 0:
    for i in d:
        j = m // i
        if (i + n) % 2 == 0 and (j + n) % 2 == 0:
            ans += binom(n, (i+n)//2) * binom(n, (j+n)//2) % mod
            ans %= mod
        i = -i
        j = m // i
        if (i + n) % 2 == 0 and (j + n) % 2 == 0:
            ans += binom(n, (i+n)//2) * binom(n, (j+n)//2) % mod
            ans %= mod
        
    print(ans * pow(pow(4, n, mod), mod-2, mod) % mod)
else:
    if n % 2 == 0:
        ans += 2 * binom(n, n//2) * pow(pow(2, n, mod),mod-2, mod) % mod
        ans %= mod
        ans -= binom(n, n//2)*binom(n, n//2) * pow(pow(4, n, mod),mod-2, mod) % mod
        ans %= mod
    print(ans)
0