結果
| 問題 | 
                            No.2724 Coprime Game 1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Jinapetto
                         | 
                    
| 提出日時 | 2024-04-12 22:48:57 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,426 bytes | 
| コンパイル時間 | 3,134 ms | 
| コンパイル使用メモリ | 254,780 KB | 
| 実行使用メモリ | 16,908 KB | 
| 最終ジャッジ日時 | 2024-10-02 23:37:49 | 
| 合計ジャッジ時間 | 4,284 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 2 WA * 5 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//多倍長整数//
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using bint = mp::cpp_int;
const int INF = 1e9;
const int MOD = 998244353;
const long long LINF = 4e18;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vvvvl = vector<vector<vector<vector<long long>>>>;
using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvvb = vector<vector<vector<bool>>>;
using vvvvb = vector<vector<vector<vector<bool>>>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(obj) (obj).begin(),(obj).end()
// エラトステネスの篩
struct Eratosthenes {
    // テーブル
    vector<bool> isprime;
    
    // 整数 i を割り切る最小の素数
    vector<int> minfactor;
    // コンストラクタで篩を回す
    Eratosthenes(int N) : isprime(N+1, true),
                          minfactor(N+1, -1) {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;
        // 篩
        for (int p = 2; p <= N; ++p) {
            // すでに合成数であるものはスキップする
            if (!isprime[p]) continue;
            // p についての情報更新
            minfactor[p] = p;
            
            // p 以外の p の倍数から素数ラベルを剥奪
            for (int q = p * 2; q <= N; q += p) {
                // q は合成数なのでふるい落とす
                isprime[q] = false;
                
                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1) minfactor[q] = p;
            }
        }
    }
    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<int,int>> factorize(int n) {
        vector<pair<int,int>> res;
        while (n > 1) {
            int p = minfactor[n];
            int exp = 0;
            // n で割り切れる限り割る
            while (minfactor[n] == p) {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }  
};
//素数列挙	O(nloglongn)
vector<int> Eratosthenes2(int n){
	vector<bool> isprime(n + 1,true);
	vector<int> prime;
	for(int i = 2;i <= n;i++){
		if(!isprime[i]) continue;
		for(int j = 2;j*i <= n;j++){
			isprime[j*i] = false;
		}
		prime.push_back(i);
	}
	return prime;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Eratosthenes er(3e6 + 10);
	vi prime = Eratosthenes2(3e6 + 10);
	int t;
	cin >> t;
	for(;t--;){
		int n;
		cin >> n;
		auto a = er.factorize(n);
		if(a.size() == 1){
			cout << "P\n";
			continue;
		}
		int cnt = n - 2;
		cnt -= upper_bound(ALL(prime),n) - upper_bound(ALL(prime),n/2);
		for(auto p : a){
			if(n/2 < p.first && p.first <= n) cnt++;
		}
		if(cnt%2 == 0) cout << "P\n";
		else cout << "K\n";
	}
	return 0;
}
            
            
            
        
            
Jinapetto