結果

問題 No.1140 EXPotentiaLLL!
ユーザー ryochansqryochansq
提出日時 2020-07-31 21:36:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,391 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 203,944 KB
実行使用メモリ 24,944 KB
最終ジャッジ日時 2023-09-20 22:08:18
合計ジャッジ時間 13,977 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,246 ms
24,736 KB
testcase_01 AC 1,274 ms
24,668 KB
testcase_02 WA -
testcase_03 AC 966 ms
24,944 KB
testcase_04 AC 743 ms
24,620 KB
testcase_05 AC 1,163 ms
24,620 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 57 ms
24,660 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 57 ms
24,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll t;
  cin >> t;
  Sieve s(5e6 + 1);
  rep(_, t) {
    ll a, p;
    cin >> a >> p;
    cout << (s.isPrime(p) ? 1 : -1) << '\n';
  }
}
0