結果

問題 No.2449 square_permutation
ユーザー rlangevin
提出日時 2023-09-09 00:55:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 320,268 KB
最終ジャッジ日時 2024-06-26 18:06:53
合計ジャッジ時間 10,853 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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