結果

問題 No.1140 EXPotentiaLLL!
ユーザー kyo1
提出日時 2020-12-27 17:46:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 193,612 KB
最終ジャッジ日時 2025-01-17 07:44:54
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

class SieveOfEratosthenes {
 private:
  std::vector<int> sieve;

 public:
  SieveOfEratosthenes(int n) : sieve(n + 1) {
    std::iota(sieve.begin(), sieve.end(), 0);
    for (int i = 2; i * i < n + 1; i++) {
      if (sieve[i] != i) continue;
      for (int j = i * i; j < n + 1; j += i) {
        if (sieve[j] == j) sieve[j] = i;
      }
    }
  }

  bool is_prime(int x) const { return x != 0 && x != 1 && sieve[x] == x; }

  std::vector<int> factor(int x) const {
    std::vector<int> res;
    while (x > 1) {
      res.emplace_back(sieve[x]);
      x /= sieve[x];
    }
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  SieveOfEratosthenes soe(10000000);
  auto solve = [&]() {
    int64_t A, P;
    cin >> A >> P;
    if (soe.is_prime(P)) {
      cout << 1 << '\n';
    } else {
      cout << -1 << '\n';
    }
  };
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}
0