結果

問題 No.2725 Coprime Game 2
コンテスト
ユーザー GOTKAKO
提出日時 2024-04-12 22:38:57
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 832 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,147 ms
コンパイル使用メモリ 215,248 KB
実行使用メモリ 11,944 KB
最終ジャッジ日時 2026-07-04 11:27:45
合計ジャッジ時間 2,292 ms
ジャッジサーバーID
(参考情報)
temp-judge_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    int T; cin >> T;
    while(T--){
        long long N; cin >> N;
        if(N == 2){cout << "P" << endl; continue;}
        int first = -1,last = -1;
        for(int i=2; i<=N; i++){
            if(N%i == 0) continue;
            if(last == -1) last = i;
            int g = gcd(N,i);
            if(g != 1) continue;
            first = i; break;
        }
        if(last == first) cout << "K" << endl;
        else{
            int now = first*2,yes = 0;
            while(now <= N){
                int g = gcd(N,now);
                if(g == 1){yes = 1; break;} 
                now += first;
            }
            if(yes) cout << "K" << endl;
            else cout << "P" << endl;
        }
    }
}
0