結果

問題 No.2724 Coprime Game 1
ユーザー umimel
提出日時 2024-05-14 20:33:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,988 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 175,620 KB
実行使用メモリ 50,284 KB
最終ジャッジ日時 2024-12-20 10:03:57
合計ジャッジ時間 25,434 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1
other TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


struct union_find{
    vector<int> par;
    vector<int> siz;
    
    union_find(int n) : par(n), siz(n, 1){
        for(int i=0; i<n; i++) par[i] = i;
    }
    
    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
 
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
 
    int size(int x){
        return siz[root(x)];
    }
};


vector<ll> cnt(3e6+1, 0);

void solve(){
    int n; cin >> n;
    if(cnt[n]%2==0) cout << "P\n";
    else cout << "K\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    union_find uf(3e6+1);
    vector<bool> isprime(1e4+1, true);
    isprime[0]=isprime[1]=false;
    for(int i=2; i<=1e4; i++){
        if(!isprime[i]) continue;
        for(int j=2*i; j<=1e4; j+=i) isprime[j] = false;
    }

    vector<int> prime;
    for(int i=2; i<=1e4; i++) if(isprime[i]) prime.pb(i);

    for(int i=2; i<=3e6; i++){
        for(int p : prime){
            if(p*p>i) break;
            if(i%p==0){
                uf.unite(p, i);
                uf.unite(p, i/p);
            }
        }
        cnt[i] = uf.size(i)-1;
    }

    int T; cin >> T;
    while(T--) solve();
}
0