結果

問題 No.1140 EXPotentiaLLL!
ユーザー kk
提出日時 2020-08-05 06:49:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 847 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 197,840 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-10-13 14:26:49
合計ジャッジ時間 10,477 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 791 ms
8,236 KB
testcase_01 AC 796 ms
8,216 KB
testcase_02 AC 814 ms
8,168 KB
testcase_03 AC 646 ms
8,380 KB
testcase_04 AC 490 ms
8,272 KB
testcase_05 AC 786 ms
8,172 KB
testcase_06 AC 759 ms
8,276 KB
testcase_07 AC 847 ms
8,280 KB
testcase_08 AC 21 ms
8,404 KB
testcase_09 AC 21 ms
8,160 KB
testcase_10 AC 22 ms
8,308 KB
testcase_11 AC 21 ms
8,164 KB
testcase_12 AC 21 ms
8,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

template <size_t N>
void psieve(bool (&p)[N]) {
  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!p[i])
      continue;
    for (int j = i * i; j < N; j += i)
      p[j] = false;
  }
}

bool prime[5000000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  psieve(prime);

  int T;
  cin >> T;
  REP (i, T) {
    long long A;
    int P;
    cin >> A >> P;
    if (!prime[P])
      cout << -1 << endl;
    else if (A % P == 0)
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
  
  return 0;
}
0