結果

問題 No.2725 Coprime Game 2
ユーザー kotatsugamekotatsugame
提出日時 2024-04-12 22:06:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 64,408 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 22:06:11
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 27 ms
6,940 KB
testcase_04 AC 40 ms
6,944 KB
testcase_05 AC 28 ms
6,940 KB
testcase_06 AC 22 ms
6,944 KB
testcase_07 AC 17 ms
6,940 KB
testcase_08 AC 25 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		long N;
		cin>>N;
		int t=2;
		while(N%t==0)t++;
		if(N<t)
		{
			cout<<"P\n";
			continue;
		}
		{
			int u=t;
			bool a=false,b=false;
			for(int p=2;p*p<=u;p++)if(u%p==0)
			{
				if(N%p==0)a=true;
				else if(t+p<N)b=true;
				while(u%p==0)u/=p;
			}
			if(u>1)
			{
				if(N%u==0)a=true;
				else if(t+u<N)b=true;
			}
			cout<<(b||!a?"K\n":"P\n");
		}
	}
}
0