結果

問題 No.2724 Coprime Game 1
ユーザー MasKoaTSMasKoaTS
提出日時 2024-01-03 21:28:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 201,680 KB
実行使用メモリ 15,764 KB
最終ジャッジ日時 2024-04-12 20:50:48
合計ジャッジ時間 4,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,336 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 242 ms
15,764 KB
testcase_04 AC 245 ms
15,640 KB
testcase_05 AC 250 ms
15,672 KB
testcase_06 AC 168 ms
15,536 KB
testcase_07 AC 239 ms
15,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
    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<bool> is_prime(n_max + 1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i * i <= n_max; ++i){
        if(!is_prime[i]){
            continue;
        }
        for(int j = i * i; j <= n_max; j += i){
            is_prime[j] = false;
        }
    }

    fenwick_tree<int> bt(n_max + 1);
    for(int i = 2; i < n_max + 1; ++i){
        bt.add(i, is_prime[i]);
    }
    for(auto& n : query){
        if(is_prime[n]){
            cout << 'P' << endl;
            continue;
        }
        int cnt = n - 2 - bt.sum(n / 2 + 1, n);
        if(cnt & 1){
            cout << 'K' << endl;
        }
        else{
            cout << 'P' << endl;
        }
    }

    return 0;
}
0