結果

問題 No.1498 Factorization from -1 to 1
ユーザー GER_chenGER_chen
提出日時 2021-05-12 00:30:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,408 ms / 3,000 ms
コード長 838 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 96,680 KB
最終ジャッジ日時 2023-10-22 05:45:20
合計ジャッジ時間 13,127 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
64,524 KB
testcase_01 AC 50 ms
64,524 KB
testcase_02 AC 50 ms
64,804 KB
testcase_03 AC 309 ms
77,180 KB
testcase_04 AC 1,408 ms
96,680 KB
testcase_05 AC 1,155 ms
91,368 KB
testcase_06 AC 1,192 ms
91,480 KB
testcase_07 AC 1,146 ms
90,268 KB
testcase_08 AC 1,172 ms
92,236 KB
testcase_09 AC 1,180 ms
91,704 KB
testcase_10 AC 116 ms
76,756 KB
testcase_11 AC 117 ms
77,060 KB
testcase_12 AC 126 ms
77,120 KB
testcase_13 AC 121 ms
77,264 KB
testcase_14 AC 126 ms
76,840 KB
testcase_15 AC 48 ms
64,544 KB
testcase_16 AC 49 ms
64,544 KB
testcase_17 AC 52 ms
64,820 KB
testcase_18 AC 49 ms
64,544 KB
testcase_19 AC 49 ms
64,544 KB
testcase_20 AC 49 ms
64,544 KB
testcase_21 AC 49 ms
64,544 KB
testcase_22 AC 49 ms
64,544 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 = [p for p in E_sieve(100001) if p%4 == 1]
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