結果

問題 No.1140 EXPotentiaLLL!
ユーザー tnakao0123tnakao0123
提出日時 2020-08-06 12:36:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 93,820 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-19 17:18:41
合計ジャッジ時間 5,494 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 206 ms
8,696 KB
testcase_01 AC 170 ms
8,632 KB
testcase_02 AC 208 ms
8,696 KB
testcase_03 AC 153 ms
8,696 KB
testcase_04 AC 121 ms
8,696 KB
testcase_05 AC 182 ms
8,696 KB
testcase_06 AC 175 ms
8,696 KB
testcase_07 AC 238 ms
8,696 KB
testcase_08 AC 19 ms
8,696 KB
testcase_09 AC 18 ms
8,696 KB
testcase_10 AC 19 ms
8,696 KB
testcase_11 AC 19 ms
8,696 KB
testcase_12 AC 19 ms
8,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1140.cc:  No.1140 EXPotentiaLLL! - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_P = 5000000;

/* typedef */

typedef long long ll;

/* global variables */

bool primes[MAX_P + 1];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  for (int p = 2; p * p <= maxp; p++)
    if (primes[p])
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}

/* main */

int main() {
  gen_primes(MAX_P);

  int t;
  scanf("%d", &t);

  while (t--) {
    ll a;
    int p;
    scanf("%lld%d", &a, &p);

    if (primes[p])
      printf("%d\n", (a % p == 0) ? 0 : 1);
    else
      puts("-1");
  }
  return 0;
}
0