結果
問題 | No.2724 Coprime Game 1 |
ユーザー |
![]() |
提出日時 | 2023-09-29 10:26:49 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 474 ms / 2,000 ms |
コード長 | 1,066 bytes |
コンパイル時間 | 2,464 ms |
コンパイル使用メモリ | 208,544 KB |
実行使用メモリ | 29,952 KB |
最終ジャッジ日時 | 2024-10-02 22:53:31 |
合計ジャッジ時間 | 5,911 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 |
ソースコード
#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 n_max = 0; for(auto& n : query){ cin >> n; if(n_max < n){ n_max = n; } } vector<int> rad(n_max + 1); for(int i = 2; i * i <= n_max; ++i){ if(rad[i] != 0){ continue; } for(int j = i * i; j <= n_max; j += i){ rad[j] = i; } } vector<char> ans(n_max + 1); dsu uni(n_max + 1); for(int n = 2; n <= n_max; ++n){ if(rad[n] == 0){ ans[n] = 'P'; continue; } int x = n; while(rad[x] != 0){ int r = rad[x]; uni.merge(n, r); while(x % r == 0){ x /= r; } } if(x > 1){ uni.merge(n, x); } ans[n] = ((uni.size(n) - 1) & 1) ? 'K' : 'P'; } for(int n : query){ cout << ans[n] << endl; } return 0; }