結果

問題 No.1140 EXPotentiaLLL!
ユーザー kappybarkappybar
提出日時 2020-07-31 22:11:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 2,241 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 171,164 KB
実行使用メモリ 24,624 KB
最終ジャッジ日時 2023-09-20 23:41:20
合計ジャッジ時間 6,171 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
24,444 KB
testcase_01 AC 243 ms
24,520 KB
testcase_02 AC 247 ms
24,384 KB
testcase_03 AC 218 ms
24,444 KB
testcase_04 AC 178 ms
24,392 KB
testcase_05 AC 246 ms
24,580 KB
testcase_06 AC 241 ms
24,512 KB
testcase_07 AC 281 ms
24,388 KB
testcase_08 AC 55 ms
24,444 KB
testcase_09 AC 57 ms
24,436 KB
testcase_10 AC 57 ms
24,516 KB
testcase_11 AC 54 ms
24,624 KB
testcase_12 AC 57 ms
24,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


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;
        }

        long long divisorCalc(long long x){
            long long res = 1;
            long long now = -1;
            long long nowCnt = 0;
            while(x != 1){
                if(now==f[x]) ++ nowCnt;
                else{
                    res *= nowCnt + 1;
                    now = f[x];
                    nowCnt = 1;
                }
                x /= f[x];
            }
            res *= nowCnt+1;
            return res;
        }
        
};

int main(){
    Sieve sieve(5000005);
    int t;
    scanf("%d",&t);
    while(t--){
        ll a,p;
        scanf("%lld %lld",&a,&p);
        if(sieve.isPrime(p)){
            a %= p;
            if(a==0) printf("%d\n",0);
            else printf("%d\n",1);
        }
        else printf("%d\n",-1);
    }
    return 0;
}
0