結果
問題 |
No.2724 Coprime Game 1
|
ユーザー |
|
提出日時 | 2024-12-20 18:24:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 1,367 bytes |
コンパイル時間 | 4,111 ms |
コンパイル使用メモリ | 276,544 KB |
実行使用メモリ | 38,504 KB |
最終ジャッジ日時 | 2024-12-20 18:24:49 |
合計ジャッジ時間 | 5,909 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h> class UnionFind { private: int n; std::vector<int> dsu; public: UnionFind(int n = 0) : n(n), dsu(n, -1) {} int find(int x) { if (dsu[x] < 0) return x; return dsu[x] = find(dsu[x]); } int unite(int x, int y) { x = find(x), y = find(y); if (x == y) return x; if (dsu[x] > dsu[y]) std::swap(x, y); dsu[x] += dsu[y]; dsu[y] = x; return x; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -dsu[find(x)]; } }; constexpr int N = 3e6; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int st[N + 1]{}; for (int i = 2; i * i <= N; ++i) { if (st[i]) continue; for (int j = i * i; j <= N; j += i) st[j] = i; } UnionFind d(N + 1); int res[N + 1]{}; for (int i = 2; i <= N; ++i) { if (st[i]) { d.unite(i, st[i]); int x = i; while (x % st[i] == 0) x /= st[i]; if (x > 1) d.unite(i, x); } res[i] = d.size(i) & 1; // res[i] = d.size(i); } int q; std::cin >> q; while (q--) { int n; std::cin >> n; // std::cout << res[n] << '\n'; std::cout << (res[n] ? "P" : "K") << '\n'; } return 0; }