結果

問題 No.1140 EXPotentiaLLL!
ユーザー mikianaaamikianaaa
提出日時 2020-09-10 16:16:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 972 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 3,812 ms
コンパイル使用メモリ 165,552 KB
実行使用メモリ 22,608 KB
最終ジャッジ日時 2023-08-25 00:16:00
合計ジャッジ時間 15,770 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 882 ms
22,400 KB
testcase_01 AC 862 ms
22,444 KB
testcase_02 AC 888 ms
22,440 KB
testcase_03 AC 756 ms
22,460 KB
testcase_04 AC 567 ms
22,296 KB
testcase_05 AC 875 ms
22,456 KB
testcase_06 AC 860 ms
22,492 KB
testcase_07 AC 972 ms
22,580 KB
testcase_08 AC 73 ms
22,608 KB
testcase_09 AC 71 ms
22,508 KB
testcase_10 AC 70 ms
22,472 KB
testcase_11 AC 71 ms
22,596 KB
testcase_12 AC 70 ms
22,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

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

    int MAX = 5 * pow(10, 6) + 5;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i])
            continue;
        for (int j = 2 * i; j < MAX; j += i)
            is_prime[j] = 0;
    }

    int T;
    cin >> T;
    rep(i, T) {
        ll a, p;
        cin >> a >> p;
        if (is_prime[p]) {
            ll gcd = GCD(a, p);
            if (gcd == 1) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}
0