結果

問題 No.1140 EXPotentiaLLL!
ユーザー NNMochiNNMochi
提出日時 2020-07-31 21:37:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,445 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 188,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 22:10:00
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
4,376 KB
testcase_01 AC 282 ms
4,376 KB
testcase_02 AC 294 ms
4,376 KB
testcase_03 AC 224 ms
4,376 KB
testcase_04 AC 195 ms
4,380 KB
testcase_05 AC 247 ms
4,380 KB
testcase_06 AC 242 ms
4,380 KB
testcase_07 AC 284 ms
4,376 KB
testcase_08 AC 108 ms
4,376 KB
testcase_09 AC 109 ms
4,376 KB
testcase_10 AC 109 ms
4,376 KB
testcase_11 AC 109 ms
4,376 KB
testcase_12 AC 109 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin >> t;
    vector<bool> is_prime(5e6+1,true);
    is_prime[0]=is_prime[1]=false;
    rep(i,5e6+1){
        if(is_prime[i]){
            ll j=2*i;
            while(j<=5e6){
                is_prime[j]=false;
              	j+=i;
            }
        }
    }
    rep(tt,t){
        ll A,P;
        cin >> A >> P;
        if(!is_prime[P]){
            cout << -1 << '\n';
        }
        else{
            if(A%P==0){
                cout << 0 << '\n';
            }
          	else{
            	cout << 1 << '\n';
            }
        }
    }
}
0