結果

問題 No.1140 EXPotentiaLLL!
ユーザー iqueue02
提出日時 2020-07-31 23:49:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,471 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 193,036 KB
最終ジャッジ日時 2025-01-12 11:56:29
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;

int is_prime[5000001];

void init () {
  fill(is_prime, is_prime + 5000009, 1);
  is_prime[0] = is_prime[1] = 0;
  for (int i = 2; i <= 5000000; i++) {
    if (!is_prime[i]) continue;
    for (int j = i + i; j <= 5000000; j += i) is_prime[j] = 0;
  }
}

int main() {
  int t;
  cin >> t;
  init();

  while (t--) {
    ll a;
    int p;
    cin >> a >> p;
    if (is_prime[p]) cout << (a % p == 0 ? 0 : 1) << "\n";
    else cout << -1 << "\n";
  }
  return 0;
} 
0