結果

問題 No.1140 EXPotentiaLLL!
ユーザー simansiman
提出日時 2023-04-12 23:23:42
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,631 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 3,232 ms
コンパイル使用メモリ 143,992 KB
実行使用メモリ 40,028 KB
最終ジャッジ日時 2024-04-17 08:37:45
合計ジャッジ時間 17,075 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,278 ms
12,380 KB
testcase_01 AC 1,210 ms
12,376 KB
testcase_02 AC 1,220 ms
12,380 KB
testcase_03 AC 1,249 ms
34,768 KB
testcase_04 AC 891 ms
29,300 KB
testcase_05 AC 1,568 ms
40,028 KB
testcase_06 AC 1,462 ms
38,616 KB
testcase_07 AC 1,631 ms
27,484 KB
testcase_08 AC 43 ms
12,380 KB
testcase_09 AC 42 ms
12,252 KB
testcase_10 AC 41 ms
12,380 KB
testcase_11 AC 43 ms
12,380 KB
testcase_12 AC 42 ms
12,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MAX_N = 5000010;
bool checked[MAX_N + 1];

class Prime {
public:
  vector<ll> prime_list;

  Prime() {
    memset(checked, false, sizeof(checked));

    for (ll i = 2; i <= MAX_N; ++i) {
      if (!checked[i]) {
        prime_list.push_back(i);

        for (ll j = 2 * i; j <= MAX_N; j += i) {
          checked[j] = true;
        }
      }
    }
  }

  map<ll, int> prime_division(ll n) {
    map<ll, int> res;

    for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
      ll p = prime_list[i];

      while (n % p == 0) {
        ++res[p];
        n /= p;
      }
    }

    if (n != 1) {
      res[n] = 1;
    }

    return res;
  }

  bool is_prime(ll n) {
    if (n <= 1) return false;

    return not checked[n];
  }
};

int main() {
  int T;
  cin >> T;

  Prime prime;
  map<ll, bool> memo;

  for (int i = 0; i < T; ++i) {
    ll A, P;
    cin >> A >> P;

    if (not memo.count(P)) {
      memo[P] = prime.is_prime(P);
    }

    if (memo[P]) {
      if (gcd(A, P) == 1) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}
0