結果

問題 No.1498 Factorization from -1 to 1
ユーザー GER_chenGER_chen
提出日時 2021-05-12 00:32:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,326 ms / 3,000 ms
コード長 813 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 95,904 KB
最終ジャッジ日時 2023-10-22 05:47:00
合計ジャッジ時間 14,612 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
62,480 KB
testcase_01 AC 47 ms
62,480 KB
testcase_02 AC 51 ms
64,804 KB
testcase_03 AC 291 ms
77,168 KB
testcase_04 AC 2,326 ms
95,904 KB
testcase_05 AC 1,718 ms
91,248 KB
testcase_06 AC 1,848 ms
92,632 KB
testcase_07 AC 1,840 ms
92,616 KB
testcase_08 AC 1,667 ms
91,872 KB
testcase_09 AC 1,800 ms
91,736 KB
testcase_10 AC 120 ms
77,052 KB
testcase_11 AC 124 ms
77,012 KB
testcase_12 AC 120 ms
76,928 KB
testcase_13 AC 118 ms
77,016 KB
testcase_14 AC 115 ms
76,892 KB
testcase_15 AC 47 ms
62,480 KB
testcase_16 AC 47 ms
62,480 KB
testcase_17 AC 52 ms
64,804 KB
testcase_18 AC 48 ms
62,480 KB
testcase_19 AC 48 ms
62,480 KB
testcase_20 AC 48 ms
62,480 KB
testcase_21 AC 49 ms
62,480 KB
testcase_22 AC 48 ms
62,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#y1498
def E_sieve(n):
    Primes = []
    if n > 1:
        Primes.append(2)
    l = (n-1)//2
    Flag = [True]*l
    for i in range(l):
        p = 2*i+3
        if not Flag[i]:
            continue
        Primes.append(p)
        for i in range((p*p-3)//2, l, p):
            Flag[i] = False
    return Primes
P = E_sieve(100001)
Memo = {}
for _ in range(int(input())):
    q = int(input())
    if Memo.get(q, 0):
        Ans = Memo[q]
    else:
        Ans = []
        x = q**2+1
        if q&1:
            x //= 2
            Ans.append(2)
        for p in P:
            if p**2 > x:
                break
            if not x%p:
                while not x%p:
                    Ans.append(p)
                    x //= p
        if x > 1:
            Ans.append(x)
        Memo[q] = Ans
    print(*Ans)
0