結果

問題 No.2724 Coprime Game 1
ユーザー inksamuraiinksamurai
提出日時 2024-04-12 22:10:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 3,791 ms
コンパイル使用メモリ 273,828 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-04-12 22:10:14
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
18,284 KB
testcase_01 AC 37 ms
18,048 KB
testcase_02 AC 37 ms
18,176 KB
testcase_03 AC 49 ms
18,280 KB
testcase_04 AC 61 ms
18,304 KB
testcase_05 AC 59 ms
18,160 KB
testcase_06 AC 49 ms
18,048 KB
testcase_07 AC 59 ms
18,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _49vEjP0 ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

const int _n=3e6;

bool bpri[_n+11];

int dp[_n+11];

void gap(){
	for(int i=2;i<=_n;i++){
		if(bpri[i]) continue;
		for(int j=2*i;j<=_n;j+=i){
			bpri[j]=1;
		}
	}
	// print(bpri[7]);
	for(int i=1;i<=_n;i++){
		dp[i]+=dp[i-1];
		dp[i]+=(!bpri[i]);
	}
}

void slv(){
	int n;
	cin>>n;

	int cnt=0;
	if(!bpri[n]){
		cnt=1;
	}else{
		cnt=n-(dp[n]-dp[n/2])-1;
	}
	// print(cnt);
	if(cnt%2){
		cout<<"P\n";
	}else{
		cout<<"K\n";
	}
}

signed main(){
_49vEjP0;
	gap();
	int __t;
	cin>>__t;
	rep(cs,__t){
		slv();
	}	
}
0