結果

問題 No.3403 Count 1210 Sequence
コンテスト
ユーザー detteiuu
提出日時 2025-12-10 01:43:24
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 1,509 ms / 2,000 ms
コード長 1,744 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 317 ms
コンパイル使用メモリ 82,880 KB
実行使用メモリ 118,680 KB
最終ジャッジ日時 2025-12-10 01:43:51
合計ジャッジ時間 22,619 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline

class Eratosthenes:
    def __init__(self, n):
        self.isPrime = [True]*(n+1)
        self.minfactor = [-1]*(n+1)
        self.isPrime[0], self.isPrime[1] = False, False
        self.minfactor[1] = 1
        for i in range(2, n+1):
            if self.isPrime[i]:
                self.minfactor[i] = i
                for j in range(i*2, n+1, i):
                    self.isPrime[j] = False
                    if self.minfactor[j] == -1:
                        self.minfactor[j] = i
    
    def factorize(self, n):
        factor = []
        while n > 1:
            p = self.minfactor[n]
            cnt = 0
            while self.minfactor[n] == p:
                n //= p
                cnt += 1
            factor.append((p, cnt))
        return factor
    
    def divisor(self, n):
        ans = [1]
        pf = self.factorize(n)
        for p, c in pf:
            L = len(ans)
            for i in range(L):
                v = 1
                for _ in range(c):
                    v *= p
                    ans.append(ans[i]*v)
        return ans

MOD = 998244353
E = Eratosthenes(202500)

L = 2025
dp = [[0]*(L+1) for _ in range(L+1)]
dp[0][0] = 1
for i in range(L):
    for j in range(L+1):
        if dp[i][j] == 0:
            continue
        if j < L:
            dp[i+1][j+1] += dp[i][j]
            dp[i+1][j+1] %= MOD
        if 1 <= j:
            dp[i+1][j-1] += dp[i][j]
            dp[i+1][j-1] %= MOD

for _ in range(int(input())):
    N, A = map(int, input().split())

    div = E.divisor(A)
    ans = 0
    for d in div:
        cnt = A//d
        if cnt <= N-1 and (N-1-cnt)%2 == 0:
            ans += dp[N-1][cnt]
            ans %= MOD
    
    print(ans)
0