結果

問題 No.2724 Coprime Game 1
ユーザー 👑 emthrmemthrm
提出日時 2024-04-12 21:55:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,312 bytes
コンパイル時間 3,663 ms
コンパイル使用メモリ 280,384 KB
実行使用メモリ 27,540 KB
最終ジャッジ日時 2024-04-12 21:56:00
合計ジャッジ時間 4,842 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
27,336 KB
testcase_01 AC 30 ms
27,512 KB
testcase_02 AC 31 ms
27,540 KB
testcase_03 AC 46 ms
27,404 KB
testcase_04 AC 59 ms
27,340 KB
testcase_05 AC 52 ms
27,540 KB
testcase_06 AC 43 ms
27,344 KB
testcase_07 AC 62 ms
27,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <bool GETS_ONLY_PRIME>
std::vector<int> prime_sieve(const int n) {
  std::vector<int> smallest_prime_factor(n + 1), prime;
  std::iota(smallest_prime_factor.begin(), smallest_prime_factor.end(), 0);
  for (int i = 2; i <= n; ++i) {
    if (smallest_prime_factor[i] == i) [[unlikely]] prime.emplace_back(i);
    for (const int p : prime) {
      if (i * p > n || p > smallest_prime_factor[i]) break;
      smallest_prime_factor[i * p] = p;
    }
  }
  return GETS_ONLY_PRIME ? prime : smallest_prime_factor;
}

struct OsaK {
  const std::vector<int> smallest_prime_factor;

  explicit OsaK(const int n) : smallest_prime_factor(prime_sieve<false>(n)) {}

  std::vector<std::pair<int, int>> query(int n) const {
    std::vector<std::pair<int, int>> res;
    while (n > 1) {
      const int prime = smallest_prime_factor[n];
      int exponent = 0;
      for (; smallest_prime_factor[n] == prime; n /= prime) {
        ++exponent;
      }
      res.emplace_back(prime, exponent);
    }
    return res;
  }
};

int main() {
  constexpr int N = 3000000;
  const OsaK osa_k(N);
  const auto is_prime = [&](const int p) -> bool {
    return osa_k.smallest_prime_factor[p] == p;
  };
  array<int, N + 1> ar{};
  FOR(i, 3, N + 1) ar[i] = ar[i - 1] + is_prime(i);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    if (is_prime(n)) {
      cout << "P\n";
    } else {
      cout << ((n - 2 - (ar[n - 1] - ar[n / 2])) % 2 == 0 ? "P\n" : "K\n");
    }
  }
  return 0;
}
0