結果

問題 No.2449 square_permutation
ユーザー 👑 rin204rin204
提出日時 2023-09-18 20:41:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 567 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 121,396 KB
最終ジャッジ日時 2023-09-18 20:41:21
合計ジャッジ時間 9,008 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,188 KB
testcase_01 AC 72 ms
71,520 KB
testcase_02 AC 72 ms
71,388 KB
testcase_03 AC 72 ms
71,484 KB
testcase_04 AC 72 ms
71,296 KB
testcase_05 AC 93 ms
76,808 KB
testcase_06 AC 144 ms
92,056 KB
testcase_07 AC 151 ms
93,848 KB
testcase_08 AC 158 ms
95,596 KB
testcase_09 AC 167 ms
98,060 KB
testcase_10 AC 198 ms
106,712 KB
testcase_11 AC 207 ms
109,024 KB
testcase_12 AC 214 ms
111,220 KB
testcase_13 AC 278 ms
120,972 KB
testcase_14 AC 250 ms
121,168 KB
testcase_15 AC 245 ms
121,324 KB
testcase_16 AC 243 ms
120,968 KB
testcase_17 AC 273 ms
121,316 KB
testcase_18 AC 234 ms
117,108 KB
testcase_19 AC 250 ms
120,468 KB
testcase_20 AC 251 ms
121,396 KB
testcase_21 AC 269 ms
121,156 KB
testcase_22 AC 71 ms
71,368 KB
testcase_23 AC 252 ms
121,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
div = [i for i in range(n + 1)]
for i in range(2, n + 1):
    if div[i] != i:
        continue
    for j in range(i * 2, n + 1, i):
        div[j] = min(div[j], i)

pp = [0] * (n + 1)
lst = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
    b = 0
    x = i
    y = 1
    while x > 1:
        d = div[x]
        if d == b:
            y *= d * d
            b = 0
        else:
            b = d
        x //= d

    pp[i] = i // y
    lst[pp[i]].append(i)

ans = [0] * n
for i in range(1, n + 1):
    ans[i - 1] = lst[pp[i]].pop()

print(*ans)
0