結果

問題 No.1498 Factorization from -1 to 1
ユーザー sgswsgsw
提出日時 2021-05-03 23:39:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 591 ms / 3,000 ms
コード長 1,018 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 120,492 KB
最終ジャッジ日時 2023-09-30 14:55:46
合計ジャッジ時間 12,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 363 ms
117,288 KB
testcase_01 AC 363 ms
117,052 KB
testcase_02 AC 373 ms
117,088 KB
testcase_03 AC 408 ms
119,036 KB
testcase_04 AC 520 ms
120,348 KB
testcase_05 AC 583 ms
119,976 KB
testcase_06 AC 591 ms
120,492 KB
testcase_07 AC 585 ms
120,472 KB
testcase_08 AC 589 ms
120,072 KB
testcase_09 AC 588 ms
119,868 KB
testcase_10 AC 410 ms
118,512 KB
testcase_11 AC 403 ms
118,348 KB
testcase_12 AC 398 ms
118,272 KB
testcase_13 AC 407 ms
118,516 KB
testcase_14 AC 408 ms
118,428 KB
testcase_15 AC 357 ms
117,284 KB
testcase_16 AC 374 ms
117,020 KB
testcase_17 AC 369 ms
117,372 KB
testcase_18 AC 367 ms
117,032 KB
testcase_19 AC 365 ms
117,016 KB
testcase_20 AC 374 ms
117,036 KB
testcase_21 AC 369 ms
117,240 KB
testcase_22 AC 373 ms
117,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys


def input():
    return sys.stdin.readline().rstrip()


MAXN = 100010
C = [i ** 2 + 1 for i in range(MAXN + 1)]


def main():
    """
    verify Code
    """
    Q = int(input())

    Query = [int(input()) for i in range(Q)]

    d = {i: defaultdict(int) for i in range(MAXN + 1)}

    for i in range(1, MAXN + 1):
        if C[i] == 1:
            continue
        p = C[i]
        for j in range(i, MAXN + 1, p):
            exp = 0
            while C[j] % p == 0:
                C[j] //= p
                exp += 1
            d[j][p] += exp
        for j in range(p - i, MAXN + 1, p):
            exp = 0
            while C[j] % p == 0:
                C[j] //= p
                exp += 1
            d[j][p] += exp

    for idx in Query:
        fact = []
        for key, value in d[idx].items():
            for _ in range(value):
                fact.append(key)
        fact.sort()
        print(*fact)

    return 0


if __name__ == "__main__":

    main()
0