結果

問題 No.2724 Coprime Game 1
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-29 10:26:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 202,812 KB
実行使用メモリ 30,008 KB
最終ジャッジ日時 2024-04-12 20:50:37
合計ジャッジ時間 5,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
29,668 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 407 ms
29,964 KB
testcase_04 AC 433 ms
29,964 KB
testcase_05 AC 419 ms
30,008 KB
testcase_06 AC 350 ms
29,824 KB
testcase_07 AC 421 ms
29,928 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 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;
}
0