結果

問題 No.1140 EXPotentiaLLL!
ユーザー yuuiyuui
提出日時 2020-08-02 02:48:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,254 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 205,972 KB
実行使用メモリ 24,944 KB
最終ジャッジ日時 2023-09-23 02:17:32
合計ジャッジ時間 14,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,254 ms
24,612 KB
testcase_01 AC 1,246 ms
24,628 KB
testcase_02 AC 1,246 ms
24,760 KB
testcase_03 AC 951 ms
24,760 KB
testcase_04 AC 747 ms
24,904 KB
testcase_05 AC 1,135 ms
24,712 KB
testcase_06 AC 1,092 ms
24,700 KB
testcase_07 AC 1,253 ms
24,760 KB
testcase_08 AC 53 ms
24,720 KB
testcase_09 AC 52 ms
24,628 KB
testcase_10 AC 52 ms
24,632 KB
testcase_11 AC 51 ms
24,612 KB
testcase_12 AC 54 ms
24,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P= pair<ll,ll>;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main() {
    ll T;
    cin >> T;
    Sieve sieve = Sieve(int(1e6)*5+5);
    for(int i=0;i<T;i++){
        ll A,P;
        cin >> A >> P;
        if(sieve.isPrime(P)){
            if(A%P ==0){
                cout << 0 << "\n";
            }else{
                cout << 1 <<"\n";
            }
        }else{
            cout << -1 << "\n";
            
        }
    }

    return 0;
}
0