結果

問題 No.1140 EXPotentiaLLL!
ユーザー zeronosu77108
提出日時 2020-08-01 00:09:42
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 1,119 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 125,824 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 22:31:50
合計ジャッジ時間 11,021 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;
using int64 = long long;

vector<bool> isPrime(6*1000000, true);

void primes(const int64 _max, vector<bool>& isPrime) {
    isPrime[0] = isPrime[1] = false;
    for (int64 i=4; i<=_max; i+=2) isPrime[i] = false;
    for (int64 i=3; i<=_max; i+=2) {
        if (!isPrime[i]) continue;
        for (int64 j=i*i; j<=_max; j+=i) {
            isPrime[j] = false;
        }
    }
}

void solve() {
    int64 a,p;
    cin >> a >> p;
    if (isPrime[p]) {
        cout << (a%p!=0) << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    int t;
    cin >> t;
    primes(5*1000000, isPrime);

    for (int i=0; i<t; i++) solve();
}
0