結果

問題 No.1140 EXPotentiaLLL!
ユーザー firiexpfiriexp
提出日時 2020-07-31 21:31:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,231 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 108,232 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-09-20 21:46:17
合計ジャッジ時間 12,662 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,223 ms
5,636 KB
testcase_01 AC 1,231 ms
5,712 KB
testcase_02 AC 1,213 ms
5,476 KB
testcase_03 AC 899 ms
5,732 KB
testcase_04 AC 693 ms
5,480 KB
testcase_05 AC 1,060 ms
5,472 KB
testcase_06 AC 1,011 ms
5,484 KB
testcase_07 AC 1,201 ms
5,636 KB
testcase_08 AC 52 ms
5,680 KB
testcase_09 AC 53 ms
5,460 KB
testcase_10 AC 52 ms
5,540 KB
testcase_11 AC 52 ms
5,712 KB
testcase_12 AC 53 ms
5,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<bool> is_prime;
vector<int> get_prime(int n){
    if(n <= 1) return vector<int>();
    is_prime.resize(n+1, true);

    vector<int> prime;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > n) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    return prime;
}
auto v = get_prime(5000001);
void solve(){
    ll a, p;
    cin >> a >> p;
    a %= p;
    if(is_prime[p]) {
        puts(a == 0 ? "0" : "1");
    }else puts("-1");
}


int main() {
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0