結果

問題 No.2724 Coprime Game 1
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-12 21:55:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,898 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 201,496 KB
実行使用メモリ 47,808 KB
最終ジャッジ日時 2024-04-12 21:55:18
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
47,720 KB
testcase_01 AC 42 ms
47,588 KB
testcase_02 AC 43 ms
47,696 KB
testcase_03 AC 181 ms
47,732 KB
testcase_04 AC 203 ms
47,808 KB
testcase_05 AC 204 ms
47,772 KB
testcase_06 AC 120 ms
47,668 KB
testcase_07 AC 194 ms
47,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using SS = int;
class SegmentTree{
    public:
    int siz = 1;
    vector<SS> dat;
 
    SS op(SS a, SS b){return a+b;}
    SS e(){return 0;}
    void renew (SS &a,SS x){
        //a = op(a,x);
        a = x;
        //その他.
    }
 
    void make(int N){
        while(siz < N) siz *= 2;
        dat.resize(siz*2,e());
    }
 
    void make2(int N,vector<SS> &A){
        make(N);
        for(int i=0; i<N; i++){
            int pos = i+siz;
            dat.at(pos) = A.at(i);
        }
        for(int i=siz-1; i>0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1));
    }
 
    void update(int pos,SS x){
        pos = pos+siz;
        renew(dat.at(pos),x);
        while(pos != 1){
            pos = pos/2;
            dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1));
        }
    }
 
SS findans(int l, int r){
    SS retl = e(),retr = e();
    l += siz,r += siz;
    while(l < r){
        if(l&1) retl = op(retl,dat.at(l++));
        if(r&1) retr = op(dat.at(--r),retr);
        l >>= 1; r >>= 1;
    }
    return op(retl,retr);
}
 
    SS get(int pos){return dat.at(pos+siz);}
    SS rangeans(int l, int r){return findans(l,r);}
    SS allrange(){return findans(0,siz);}
 
    //ノーマルセグ木 二分探索は実装してない.
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T; cin >> T;
    int Need = 3e6+9;
    vector<int> prime(Need+1,1);
    prime.at(0) = 0; prime.at(1) = 0;
    for(int i=2; i*i<=Need; i++){
        if(!prime.at(i)) continue;
        for(int k=i*i; k<=Need; k+=i) prime.at(k) = 0;
    }
    SegmentTree Z; Z.make2(Need+1,prime);

    while(T--){
        int N; cin >> N;
        if(prime.at(N)){cout << "P" << endl; continue;}
        int p = Z.rangeans(N/2+1,N);
        N -= p; N -= 2;
        if(N%2) cout << "K" << endl;
        else cout << "P" << endl;

    }
}
0