結果

問題 No.1140 EXPotentiaLLL!
ユーザー lorent_kyoprolorent_kyopro
提出日時 2020-08-01 03:39:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 895 ms / 2,000 ms
コード長 2,198 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 202,868 KB
実行使用メモリ 24,740 KB
最終ジャッジ日時 2023-09-21 08:47:20
合計ジャッジ時間 11,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 840 ms
24,452 KB
testcase_01 AC 844 ms
24,668 KB
testcase_02 AC 851 ms
24,656 KB
testcase_03 AC 708 ms
24,452 KB
testcase_04 AC 542 ms
24,520 KB
testcase_05 AC 842 ms
24,392 KB
testcase_06 AC 802 ms
24,740 KB
testcase_07 AC 895 ms
24,516 KB
testcase_08 AC 51 ms
24,656 KB
testcase_09 AC 50 ms
24,448 KB
testcase_10 AC 52 ms
24,520 KB
testcase_11 AC 51 ms
24,600 KB
testcase_12 AC 50 ms
24,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1) : n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (long long i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (long long j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;}
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
} sieve(5e6);

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

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

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