結果

問題 No.2449 square_permutation
ユーザー kotatsugamekotatsugame
提出日時 2023-09-19 19:45:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 64,376 KB
実行使用メモリ 5,092 KB
最終ジャッジ日時 2023-09-19 19:46:03
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 24 ms
4,516 KB
testcase_12 AC 26 ms
4,516 KB
testcase_13 AC 32 ms
4,776 KB
testcase_14 AC 32 ms
4,916 KB
testcase_15 AC 33 ms
4,940 KB
testcase_16 AC 32 ms
4,856 KB
testcase_17 AC 32 ms
4,860 KB
testcase_18 AC 29 ms
4,660 KB
testcase_19 AC 32 ms
4,848 KB
testcase_20 AC 33 ms
4,788 KB
testcase_21 AC 33 ms
4,852 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 33 ms
5,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
using namespace std;
int N;
int P[3<<17];
bool used[3<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=1;i<=N;i++)P[i]=i;
	for(int u=2;u*u<=N;u++)
	{
		int t=u*u;
		for(int v=t;v<=N;v+=t)while(P[v]%t==0)P[v]/=t;
	}
	for(int i=1;i<=N;i++)
	{
		int t=P[i],av=-1;
		for(int v=1;t*v*v<=N;v++)if(!used[t*v*v])av=v;
		assert(av!=-1);
		int v=av;
		cout<<t*v*v<<(i==N?"\n":" ");
		used[t*v*v]=true;
	}
}
0