結果

問題 No.2724 Coprime Game 1
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-29 10:14:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 200,580 KB
実行使用メモリ 18,652 KB
最終ジャッジ日時 2024-04-12 20:50:31
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
18,216 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 193 ms
18,652 KB
testcase_04 AC 199 ms
18,648 KB
testcase_05 AC 195 ms
18,592 KB
testcase_06 AC 110 ms
18,572 KB
testcase_07 AC 182 ms
18,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(void){
    int t;    cin >> t;
    vector<int> query(t);

    int n_max = 0;
    for(auto& n : query){
        cin >> n;
        if(n_max < n){
            n_max = n;
        }
    }

    vector<bool> is_prime(n_max + 1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i * i <= n_max; ++i){
        if(!is_prime[i]){
            continue;
        }
        for(int j = i * i; j <= n_max; j += i){
            is_prime[j] = false;
        }
    }

    vector<int> dp(n_max + 1);
    vector<char> ans(n_max + 1);
    for(int n = 2; n <= n_max; n++){
        dp[n] = dp[n - 1];
        if(is_prime[n]){
            dp[n]++;
            ans[n] = 'P';
            continue;
        }
        ans[n] = (((n - 2) - dp[n] + dp[n / 2]) & 1) ? 'K' : 'P';
    }

    for(int n : query){
        cout << ans[n] << endl;
    }

    return 0;
}
0