結果

問題 No.2449 square_permutation
ユーザー rlangevinrlangevin
提出日時 2023-09-09 00:55:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 318,972 KB
最終ジャッジ日時 2023-09-09 00:55:43
合計ジャッジ時間 14,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,860 KB
testcase_01 AC 88 ms
71,920 KB
testcase_02 AC 87 ms
71,536 KB
testcase_03 AC 88 ms
71,596 KB
testcase_04 AC 94 ms
71,984 KB
testcase_05 AC 104 ms
78,216 KB
testcase_06 AC 277 ms
159,464 KB
testcase_07 AC 267 ms
167,920 KB
testcase_08 AC 285 ms
178,488 KB
testcase_09 AC 307 ms
189,572 KB
testcase_10 AC 407 ms
236,828 KB
testcase_11 AC 405 ms
249,484 KB
testcase_12 AC 449 ms
261,612 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 94 ms
71,596 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return sorted(list(S))

N = int(input())
S = []
for i in Sieve(500):
    S.append(i * i)
    
L = []
for i in range(N + 1):
    L.append([i, i])
    
for s in S:
    now = s
    while now <= N + 1:
        for i in range(now, N + 1, now):
            L[i][0] //= s
        now *= s
        
from collections import *
ans = list(range(N + 1))
D = [deque() for i in range(N + 1)]
for i in range(N + 1):
    D[L[i][0]].append(L[i][1])
    
for i in range(1, N + 1):
    while len(D[i]) >= 2:
        a = D[i].popleft()
        b = D[i].pop()
        ans[a], ans[b] = ans[b], ans[a]
        
print(*ans[1:])
0