結果

問題 No.1140 EXPotentiaLLL!
ユーザー Ricky_ponRicky_pon
提出日時 2020-07-31 21:31:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,821 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 204,528 KB
実行使用メモリ 24,684 KB
最終ジャッジ日時 2023-09-20 21:49:02
合計ジャッジ時間 6,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
24,420 KB
testcase_01 AC 211 ms
24,684 KB
testcase_02 AC 255 ms
24,592 KB
testcase_03 AC 199 ms
24,680 KB
testcase_04 AC 160 ms
24,472 KB
testcase_05 AC 230 ms
24,544 KB
testcase_06 AC 220 ms
24,672 KB
testcase_07 AC 290 ms
24,608 KB
testcase_08 AC 61 ms
24,680 KB
testcase_09 AC 70 ms
24,412 KB
testcase_10 AC 64 ms
24,504 KB
testcase_11 AC 63 ms
24,616 KB
testcase_12 AC 62 ms
24,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 500010;

vector<int> min_factor, prime;

void sieve(int n){
    min_factor.resize(n+1, 0);
    For(i, 2, n+1){
        if(min_factor[i] == 0){
            min_factor[i] = i;
            prime.push_back(i);
        }
        for(int x: prime){
            if(x*i > n || x > i) break;
            min_factor[x*i] = x;
        }
    }
}

bool is_prime(int x){
    return min_factor[x] == x;
}

vector<pii> prime_factor(int n){
    vector<pii> ret;
    while(n > 1){
        if(ret.empty() || ret.rbegin()->fi != min_factor[n]){
            ret.emplace_back(min_factor[n], 1);
        }
        else ++ret.rbegin()->se;
        n /= min_factor[n];
    }
    return ret;
}

void solve(){
    lint a;
    int p;
    scanf("%lld%d", &a, &p);
    if(!is_prime(p)){
        puts("-1");
        return;
    }
    printf("%d\n", a % p != 0);
}

int main(){
    sieve(5000010);
    int t;
    scanf("%d", &t);
    rep(tt, t){
        solve();
    }
}
0