結果

問題 No.1140 EXPotentiaLLL!
ユーザー risujirohrisujiroh
提出日時 2020-07-31 21:46:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 203,340 KB
実行使用メモリ 5,448 KB
最終ジャッジ日時 2023-09-20 22:43:15
合計ジャッジ時間 5,850 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
5,256 KB
testcase_01 AC 186 ms
5,268 KB
testcase_02 AC 196 ms
5,140 KB
testcase_03 AC 185 ms
5,124 KB
testcase_04 AC 146 ms
5,256 KB
testcase_05 AC 222 ms
5,312 KB
testcase_06 AC 212 ms
5,148 KB
testcase_07 AC 261 ms
5,140 KB
testcase_08 AC 21 ms
5,380 KB
testcase_09 AC 22 ms
5,328 KB
testcase_10 AC 22 ms
5,448 KB
testcase_11 AC 22 ms
5,268 KB
testcase_12 AC 22 ms
5,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

vector<int> sieve(int n) {
  vector<bool> b(n / 3 + 1, true);
  vector<int> res{2, 3};
  for (int p = 5, d = 4; p * p <= n; p += d = 6 - d) if (b[p / 3])
    for (int i = p * p, di = p % 3 * 2 * p; i <= n; i += di = 6 * p - di)
      b[i / 3] = false;
  for (int p = 5, d = 4; p <= n; p += d = 6 - d) if(b[p / 3]) res.push_back(p);
  while (not res.empty() and res.back() > n) res.pop_back();
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  auto primes = sieve(5e6);
  int tt;
  cin >> tt;
  using ll = long long;
  while (tt--) {
    ll a;
    cin >> a;
    int p;
    cin >> p;
    if (binary_search(begin(primes), end(primes), p)) {
      if (a % p) {
        cout << "1\n";
      } else {
        cout << "0\n";
      }
    } else {
      cout << "-1\n";
    }
  }
}
0