結果

問題 No.2725 Coprime Game 2
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-12 23:01:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,264 bytes
コンパイル時間 2,785 ms
コンパイル使用メモリ 206,028 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 23:01:30
合計ジャッジ時間 4,500 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 168 ms
6,940 KB
testcase_04 AC 189 ms
6,940 KB
testcase_05 AC 172 ms
6,940 KB
testcase_06 AC 160 ms
6,940 KB
testcase_07 AC 103 ms
6,944 KB
testcase_08 AC 163 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Need = 100;
    vector<vector<pair<int,int>>> Pf(Need+1);
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i<=Need; i++){
        if(!prime.at(i)) continue;
        Pf.at(i) = {{i,1}};
        for(int k=i+i; k<=Need; k+=i){
            prime.at(k) = false;
            int f = 0,k2 = k;
            while(k2%i == 0) f++,k2 /= i;
            Pf.at(k).push_back({i,f});
        }
    }

    int T; cin >> T;
    while(T--){
        long long N = 72201776446800LL; cin >> N;
        if(N == 2){cout << "P" << endl; continue;}
        int first = -1;
        for(int i=2; i<=N; i++){
            if(N%i == 0) continue;
            first = i; break;
        }

        int now = first,yes = 0,add = 1;
        for(auto [p,e] : Pf.at(now)) add *= p;
        if(gcd(gcd(now,N),gcd(add,N)) != 1){cout << "P" << endl; continue;}
        
        while(now < N){
            if(N%now){
                int g = gcd(now,N);
                if(g == 1){yes = 1; break;}
            }
            now += add;
        }

        if(yes) cout << "K" << endl; 
        else cout << "P" << endl;
    }
}
0