結果

問題 No.1140 EXPotentiaLLL!
ユーザー tsugutsugutsugutsugu
提出日時 2020-08-01 14:18:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 2,572 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 166,128 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2023-09-22 09:21:36
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 230 ms
8,376 KB
testcase_01 AC 222 ms
8,384 KB
testcase_02 AC 232 ms
8,388 KB
testcase_03 AC 179 ms
8,424 KB
testcase_04 AC 144 ms
8,424 KB
testcase_05 AC 209 ms
8,552 KB
testcase_06 AC 196 ms
8,476 KB
testcase_07 AC 244 ms
8,360 KB
testcase_08 AC 41 ms
8,344 KB
testcase_09 AC 41 ms
8,480 KB
testcase_10 AC 42 ms
8,388 KB
testcase_11 AC 41 ms
8,380 KB
testcase_12 AC 39 ms
8,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mxN = 5e6 + 3;
bool prime[mxN];

void settable() {
    prime[0] = prime[1] = 0;
    for(int i = 2; i < mxN; i++) {
        if(prime[i]) {
            for(int j = i + i; j < mxN; j += i) {
                prime[j] = false;
            }
        }
    }
}

void solve() {
    ll a; int p;
    cin >> a >> p;
    if(!prime[p]) {
        printf("%d\n", -1);
    }else{
        if(a % p == 0) printf("%d\n", 0);
        else printf("%d\n", 1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(prime, 1, sizeof(prime));
    settable();
    int t;
    cin >> t;
    while(t--) solve();
}
0