結果
問題 |
No.2449 square_permutation
|
ユーザー |
![]() |
提出日時 | 2023-09-09 00:56:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 599 ms / 2,000 ms |
コード長 | 890 bytes |
コンパイル時間 | 503 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 320,284 KB |
最終ジャッジ日時 | 2024-06-26 18:07:10 |
合計ジャッジ時間 | 11,640 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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(5000): 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:])