結果

問題 No.1140 EXPotentiaLLL!
ユーザー karinohitokarinohito
提出日時 2022-05-14 12:59:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 890 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 200,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 03:51:57
合計ジャッジ時間 10,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 844 ms
4,376 KB
testcase_01 AC 824 ms
4,376 KB
testcase_02 AC 849 ms
4,380 KB
testcase_03 AC 648 ms
4,376 KB
testcase_04 AC 506 ms
4,380 KB
testcase_05 AC 789 ms
4,376 KB
testcase_06 AC 756 ms
4,376 KB
testcase_07 AC 890 ms
4,376 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 37 ms
4,384 KB
testcase_10 AC 38 ms
4,380 KB
testcase_11 AC 37 ms
4,380 KB
testcase_12 AC 37 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


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


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

    
    ll M=5e6+10;
    vector<bool> P(M,true);
    P[0]=P[1]=0;
    rep(i,M){
        if(P[i]){
            for(ll j=i*2;j<M;j+=i)P[j]=0;
        }
    }

    ll T;
    cin>>T;
    rep(i,T){
        ll A,N;
        cin>>A>>N;
        if(P[N]){
            cout<<(gcd(A,N)==1)<<endl;
        }
        else cout<<-1<<endl;
    }



}
0