結果

問題 No.1140 EXPotentiaLLL!
ユーザー tsugutsugutsugutsugu
提出日時 2020-08-01 20:35:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 165,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 14:40:54
合計ジャッジ時間 5,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
4,380 KB
testcase_01 AC 219 ms
4,380 KB
testcase_02 AC 227 ms
4,376 KB
testcase_03 AC 166 ms
4,380 KB
testcase_04 AC 135 ms
4,376 KB
testcase_05 AC 194 ms
4,380 KB
testcase_06 AC 185 ms
4,380 KB
testcase_07 AC 223 ms
4,380 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 34 ms
4,376 KB
testcase_10 AC 35 ms
4,380 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 35 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Sieve {
    vector<bool> isprime;
    int n;
    Sieve(int n_) : isprime(n_ + 1, true), n(n_) {};
    void build() {
        isprime[0] = isprime[1] = false;
        for(int i = 2; i <= n; i++) {
            if(isprime[i]) {
                for(int j = i + i; j <= n; j += i) {
                    isprime[j] = false;
                }
            }
        }
    }
    bool isp(int i) {
        return isprime[i];
    }
};

const int mxN = 5e6;

int main() {
    Sieve P(mxN);
    P.build();
    int t;
    cin >> t;
    while(t--) {
        ll a; int p;
        scanf("%lld%d", &a, &p);
        if(!P.isp(p)) {
            printf("%d\n", -1);
        }else{
            if(a % p == 0) printf("%d\n", 0);
            else printf("%d\n", 1);
        }
    }
}
0