結果

問題 No.1140 EXPotentiaLLL!
ユーザー けーむけーむ
提出日時 2020-08-04 11:31:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,720 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 175,292 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 11:36:38
合計ジャッジ時間 7,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
4,352 KB
testcase_01 AC 199 ms
4,348 KB
testcase_02 AC 218 ms
4,352 KB
testcase_03 AC 145 ms
4,348 KB
testcase_04 AC 114 ms
4,348 KB
testcase_05 AC 172 ms
4,348 KB
testcase_06 AC 166 ms
4,348 KB
testcase_07 AC 254 ms
4,352 KB
testcase_08 AC 20 ms
4,348 KB
testcase_09 AC 20 ms
4,348 KB
testcase_10 AC 20 ms
4,352 KB
testcase_11 AC 20 ms
4,348 KB
testcase_12 AC 21 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct isPrime {
private:
    vector<bool> data;
    
public:
    isPrime() {}
    isPrime(int n) {
        data.resize(n + 1, true);
        data[0] = data[1] = false;
        for(long long i = 2; (i * i) <= n; i++) {
            if (!data[i]) continue;
            for(long long j = 2; (i * j) <= n; j++) {
                data[i * j] = false;
            }
        }
    }
    
    bool is_prime(int n) {
        return data[n];
    }
    
    vector<int> get_primes_vector() {
        vector<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.push_back(i);
        }
        return ans;
    }
    
    set<int> get_primes_set() {
        set<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.insert(i);
        }
        return ans;
    }
};

isPrime ip(5 * 1e6);

void solve() {
    ll a, p;
    cin >> a >> p;
    if (!ip.is_prime(p)) {
        cout << -1 << endl;
        return;
    }
    cout << ((__gcd(a, p) == 1) ? 1 : 0) << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll t;
    cin >> t;
    rep(i, t) solve();
    return 0;
}
0