結果

問題 No.2724 Coprime Game 1
ユーザー ttkkggww
提出日時 2024-05-05 20:06:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,864 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 4,248 ms
コンパイル使用メモリ 251,976 KB
最終ジャッジ日時 2025-02-21 11:05:00
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;

ll all_stones[3000001];
vector<int> primes[3000001];

void init(){
    for(int i = 2;i<=3000000;++i){
        if(primes[i].size()==0){
            for(int j = i;j<=3000000;j+=i){
                primes[j].push_back(i);
            }
        }
    }
    dsu d(3000001);
    for(int i = 2;i<=3000000;++i){
        for(auto p : primes[i]){
            d.merge(i,p);
        }
        all_stones[i] = d.size(i);
    }
}

ll N;

void solve(){
    if(all_stones[N]%2==0){
        cout<<"K"<<'\n';
    }else{
        cout<<"P"<<"\n";
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int T;
    cin >> T;
    while(T--){
        cin >> N;
        solve();
    }
}
0