結果

問題 No.3776 Magic Square of Product
コンテスト
ユーザー LyricalMaestro
提出日時 2026-10-24 15:22:13
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 315 ms / 2,500 ms
+ 376µs
コード長 1,628 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 91 ms
コンパイル使用メモリ 64,844 KB
実行使用メモリ 89,248 KB
最終ジャッジ日時 2026-10-24 15:22:21
合計ジャッジ時間 7,604 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3776

MOD = 998244353


def main():
    T = int(input())
    K = []
    for _ in range(T):
        K.append(int(input()))

    max_k = max(K) + 1
    # osa-k法
    primes = [k for k in range(max_k + 1)]
    for p in range(2, max_k + 1):
        if primes[p] != p:
            continue

        x = 2 * p
        while x <= max_k:
            if primes[x] == x:
                primes[x] = p
            x += p

    # 本格的に解く
    answer_cache = [-1] * (max_k + 1)
    for k in K:
        if answer_cache[k] != -1:
            print(answer_cache[k])
            continue

        k0 = k
        p_map = {}
        while k0 > 1:
            p = primes[k0]
            k0 //= p
            if p not in p_map:
                p_map[p] = 0
            p_map[p] += 1

        answer = 1
        for value in p_map.values():
            array = []
            for x in range(value + 1):
                for y in range(value + 1):
                    if value - (x + y) >= 0:
                        z = value - (x + y)
                        array.append((x, y, z))
            ans = 0
            for x11, x12, x13 in array:
                for x21, x22, x23 in array:
                    x = value - x11 - x21
                    y = value - x12 - x22
                    z = value - x13 - x23
                    if x >= 0 and y>= 0 and z >= 0 and x + y + z == value:
                        ans += 1
            answer *= ans
            answer %= MOD
        answer_cache[k] = answer
        print(answer)
                    

        









if __name__ == "__main__":
    main()
0