結果

問題 No.1140 EXPotentiaLLL!
ユーザー yakkiyakki
提出日時 2020-07-31 21:52:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,219 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 122,508 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 23:00:38
合計ジャッジ時間 12,900 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,219 ms
4,376 KB
testcase_01 AC 1,207 ms
4,376 KB
testcase_02 AC 1,211 ms
4,376 KB
testcase_03 AC 885 ms
4,380 KB
testcase_04 AC 666 ms
4,380 KB
testcase_05 AC 1,064 ms
4,376 KB
testcase_06 AC 1,002 ms
4,376 KB
testcase_07 AC 1,179 ms
4,380 KB
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 32 ms
4,380 KB
testcase_10 AC 32 ms
4,376 KB
testcase_11 AC 33 ms
4,380 KB
testcase_12 AC 32 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
    int t; cin >> t;
    sieve(5000005);
    while(t--){
        ll a; cin >> a;
        int p; cin >> p;
        if(!IsPrime[p]) cout << -1 << endl;
        else{
            if(a % p == 0) cout << 0 << endl;
            else cout << 1 << endl;
        }
    }
} 

0