結果

問題 No.1140 EXPotentiaLLL!
ユーザー ryochansqryochansq
提出日時 2020-07-31 23:26:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,239 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 203,232 KB
実行使用メモリ 28,852 KB
最終ジャッジ日時 2023-09-21 02:59:35
合計ジャッジ時間 14,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,227 ms
28,504 KB
testcase_01 AC 1,221 ms
28,524 KB
testcase_02 AC 1,237 ms
28,704 KB
testcase_03 AC 928 ms
28,664 KB
testcase_04 AC 727 ms
28,572 KB
testcase_05 AC 1,145 ms
28,536 KB
testcase_06 AC 1,077 ms
28,568 KB
testcase_07 AC 1,239 ms
28,520 KB
testcase_08 AC 61 ms
28,604 KB
testcase_09 AC 60 ms
28,528 KB
testcase_10 AC 66 ms
28,508 KB
testcase_11 AC 65 ms
28,852 KB
testcase_12 AC 62 ms
28,536 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 si(6000000);
  rep(_, t) {
    ll a, p;
    cin >> a >> p;
    if(si.isPrime(p))
      cout << int(a % p > 0) << '\n';
    else
      cout << -1 << '\n';
  }
}
0