結果

問題 No.2724 Coprime Game 1
ユーザー MasKoaTSMasKoaTS
提出日時 2023-04-09 15:14:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 204,172 KB
実行使用メモリ 30,032 KB
最終ジャッジ日時 2024-04-12 20:50:29
合計ジャッジ時間 5,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
29,552 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 436 ms
29,964 KB
testcase_04 AC 450 ms
30,032 KB
testcase_05 AC 443 ms
29,944 KB
testcase_06 AC 355 ms
29,804 KB
testcase_07 AC 432 ms
29,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;


int main(void) {
	int t;	cin >> t;
	vector<int> query(t);
	int m = 0;
	for (int i = 0; i < t; i++) {
		cin >> query[i];
		if (m < query[i]) {
			m = query[i];
		}
	}

	vector<int> rad(m + 1);
	for (int i = 2; i * i <= m; i++) {
		if (rad[i] != 0) {
			continue;
		}
		for (int j = i * i; j <= m; j += i) {
			rad[j] = i;
		}
	}

	vector<char> ans(m + 1);
	dsu uni(m + 1);
	for (int n = 2; n <= m; n++) {
		if (rad[n] == 0) {
			ans[n] = 'P';
			continue;
		}
		int k = n;
		while (rad[k] != 0) {
			uni.merge(n, rad[k]);
			int d = rad[k];
			while (k % d == 0) {
				k /= d;
			}
		}
		if (k > 1) {
			uni.merge(n, k);
		}
		ans[n] = ((uni.size(n) - 1) & 1) ? 'K' : 'P';
	}

	for (int n : query) {
		cout << ans[n] << endl;
	}

	return 0;
}
0