結果

問題 No.1140 EXPotentiaLLL!
ユーザー hayatenhayaten
提出日時 2020-07-31 23:21:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,255 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 165,580 KB
実行使用メモリ 11,788 KB
最終ジャッジ日時 2023-09-21 02:52:25
合計ジャッジ時間 13,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,250 ms
11,604 KB
testcase_01 AC 1,226 ms
11,500 KB
testcase_02 AC 1,236 ms
11,656 KB
testcase_03 AC 927 ms
11,504 KB
testcase_04 AC 714 ms
11,628 KB
testcase_05 AC 1,119 ms
11,504 KB
testcase_06 AC 1,056 ms
11,540 KB
testcase_07 AC 1,255 ms
11,468 KB
testcase_08 AC 40 ms
11,528 KB
testcase_09 AC 40 ms
11,576 KB
testcase_10 AC 39 ms
11,788 KB
testcase_11 AC 39 ms
11,608 KB
testcase_12 AC 40 ms
11,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

const ll MAX_N = 5000000;
ll prime[MAX_N];
bool is_prime[MAX_N + 1];

//エラトステネスの篩
void sieve(ll n){
  ll p = 0;
  n = MAX_N;
  for (ll i = 0; i <= n; i++)is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (ll i = 2; i <= n; i++){
    if(is_prime[i]){
      prime[p++] = i;
      for (ll j = 2 * i; j <= n; j += i)is_prime[j] = false;
    }
  }
}


long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

void solve() {
  ll a, p;
  cin >> a >> p;
  if(!is_prime[p]){
    cout << -1 << endl;
    return;
  }
  if(gcd(a, p) != 1){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
  return;
}

int main(){
  sieve(MAX_N);
  int t;
  cin >> t;
  rep(i, t) solve();
}
0