結果

問題 No.1140 EXPotentiaLLL!
ユーザー outlineoutline
提出日時 2020-12-18 04:55:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 137,800 KB
実行使用メモリ 22,724 KB
最終ジャッジ日時 2023-10-21 07:51:39
合計ジャッジ時間 6,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 254 ms
22,724 KB
testcase_01 AC 254 ms
22,724 KB
testcase_02 AC 270 ms
22,724 KB
testcase_03 AC 230 ms
22,724 KB
testcase_04 AC 193 ms
22,724 KB
testcase_05 AC 258 ms
22,724 KB
testcase_06 AC 253 ms
22,724 KB
testcase_07 AC 291 ms
22,724 KB
testcase_08 AC 81 ms
22,724 KB
testcase_09 AC 81 ms
22,724 KB
testcase_10 AC 82 ms
22,724 KB
testcase_11 AC 80 ms
22,724 KB
testcase_12 AC 83 ms
22,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct ExtendedSieve{
    vector<int> table;
    const int n;

    ExtendedSieve(int n) : n(n) {
        table.assign(n + 1, 0);
        table[0] = table[1] = 1;
        for(int i = 2; i <= n; ++i){
            if(table[i] > 0)    continue;
            table[i] = i;
            for(int j = i + i; j <= n; j += i){
                if(table[j] == 0)   table[j] = i;
            }
        }
    }

    bool is_prime(int x){
        if(x < 2)   return false;
        return x == table[x];
    }

    map<int, int> prime_factorization(int x){
        map<int, int> res;
        while(x > 1){
            ++res[table[x]];
            x /= table[x];
        }
        return res;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    ExtendedSieve sieve(5000000);
    for(int loop = 0; loop < T; ++loop){
        ll a;
        int p;
        cin >> a >> p;
        if(!sieve.is_prime(p))  cout << -1 << '\n';
        else{
            if(a % p == 0)  cout << 0 << '\n';
            else    cout << 1 << '\n';
        }
    }

    return 0;
}
0