結果

問題 No.1140 EXPotentiaLLL!
ユーザー tabae326tabae326
提出日時 2020-07-31 23:28:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,366 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 164,992 KB
実行使用メモリ 8,436 KB
最終ジャッジ日時 2023-09-21 03:00:58
合計ジャッジ時間 14,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,345 ms
8,248 KB
testcase_01 AC 1,331 ms
8,436 KB
testcase_02 AC 1,350 ms
8,232 KB
testcase_03 AC 1,035 ms
8,244 KB
testcase_04 AC 823 ms
8,308 KB
testcase_05 AC 1,226 ms
8,260 KB
testcase_06 AC 1,154 ms
8,244 KB
testcase_07 AC 1,366 ms
8,420 KB
testcase_08 AC 170 ms
8,280 KB
testcase_09 AC 165 ms
8,296 KB
testcase_10 AC 166 ms
8,248 KB
testcase_11 AC 168 ms
8,308 KB
testcase_12 AC 168 ms
8,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

#define NMAX 5000100
bool primes[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

ll gcd(ll a, ll b){
    if(a < b) return gcd(b, a);
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    ll ret = a / gcd(a,b) * b;
    return ret;
}

int main(){
    rep(i, 2, NMAX) primes[i] = true;
    rep(i, 2, NMAX) {
        for(ll j = i * 2; j <= NMAX; j += i) primes[j] = false;
    }
    ll T = 0;
    cin >> T;
    rep(test, 0, T){
        ll a, p;
        cin >> a >> p;
        if(!primes[p]) {
            cout << -1 << endl;
            continue;
        }
        if(gcd(a, p) == 1) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}
0