結果

問題 No.2449 square_permutation
ユーザー kotatsugame
提出日時 2023-09-19 19:45:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 63,872 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 21:44:07
合計ジャッジ時間 3,782 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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