結果

問題 No.1140 EXPotentiaLLL!
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-07-31 23:09:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,221 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 1,319 ms
コンパイル使用メモリ 152,084 KB
実行使用メモリ 6,020 KB
最終ジャッジ日時 2023-09-21 02:17:58
合計ジャッジ時間 12,833 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,221 ms
5,640 KB
testcase_01 AC 1,192 ms
5,708 KB
testcase_02 AC 1,209 ms
5,764 KB
testcase_03 AC 863 ms
5,844 KB
testcase_04 AC 669 ms
5,844 KB
testcase_05 AC 1,042 ms
5,820 KB
testcase_06 AC 986 ms
5,976 KB
testcase_07 AC 1,181 ms
5,720 KB
testcase_08 AC 36 ms
5,704 KB
testcase_09 AC 36 ms
6,020 KB
testcase_10 AC 36 ms
5,988 KB
testcase_11 AC 36 ms
5,828 KB
testcase_12 AC 36 ms
5,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.07.31 23:09:32
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



struct Eratosthenes {
private:
    int N;
public:
    std::vector< bool > isprime;
    std::vector< int > prime;
    Eratosthenes(int n) : N(n) {
        isprime.resize(N + 1, true);
        isprime[0] = isprime[1] = false;
        for (int i = 2; i * i <= N; i++) {
            if (isprime[i]) {
                for (int j = i + i; j <= N; j += i) {
                    isprime[j] = false;
                }
            }
        }
        for (int i = 2; i <= N; i++) {
            if (isprime[i]) {
                prime.push_back(i);
            }
        }
    }
};
int main() {
    int t;cin >> t;
    Eratosthenes era(5 * 1000000);
    while(t--) {
        ll a, p;
        cin >> a >> p;
        if (era.isprime[p]) {
            if (a % p == 0) {
                cout << 0 << endl;
            }
            else {
                cout << 1 << endl;
            }
        }
        else {
            cout << -1 << endl;
        }
    }
    return 0;
}
0