結果

問題 No.1140 EXPotentiaLLL!
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-29 03:58:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 673 ms / 2,000 ms
コード長 2,113 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 132,760 KB
実行使用メモリ 63,744 KB
最終ジャッジ日時 2023-10-29 03:58:14
合計ジャッジ時間 11,561 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 630 ms
63,744 KB
testcase_01 AC 648 ms
63,744 KB
testcase_02 AC 634 ms
63,744 KB
testcase_03 AC 602 ms
63,744 KB
testcase_04 AC 568 ms
63,744 KB
testcase_05 AC 642 ms
63,744 KB
testcase_06 AC 624 ms
63,744 KB
testcase_07 AC 673 ms
63,744 KB
testcase_08 AC 453 ms
63,744 KB
testcase_09 AC 457 ms
63,744 KB
testcase_10 AC 454 ms
63,744 KB
testcase_11 AC 456 ms
63,744 KB
testcase_12 AC 456 ms
63,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
struct Eratosthenes {
    vector<int> isp,minfactor,myprime,moebius;

    Eratosthenes (int n) : isp(n+1,1),minfactor(n+1,__INT_MAX__),moebius(n+1,1){

        isp[0] = isp[1] = 0;
        minfactor[0] = 0;minfactor[1] = 1;

        for(int p = 2;p <= n;p++){
            if(!isp[p]) continue;
            minfactor[p] = p;
            moebius[p] = -1;
            myprime.push_back(p);

            for(int q = 2*p;q <= n;q += p){
                isp[q] = false;

                if(!((q/p)%p)) moebius[q] = 0;
                else moebius[q] = -moebius[q];


                minfactor[q] = min(minfactor[q],p);
            }
        }
    }

    vector<pair<int,int>> prime_factorize(int n) {
        vector<pair<int,int>> res;
        while(n-1){

            int p = minfactor[n];
            int exp = 0;

            while(minfactor[n] == p){
                n /= p;
                exp ++;
            }

            res.push_back(make_pair(p,exp));
        }

        return res;
    }

    vector<int> divisors(int n){
        vector<int> res;
        res.push_back(1);

        auto pf = prime_factorize(n);

        for(auto [p,e]:pf){
            int s = (int)res.size();

            for(int i = 0;i < s;i++){
                int v = 1;
                for(int j = 0;j < e;j++){
                    v *= p;
                    res.push_back(res[i]*v);
                }
            }
        }

        return res;
    }
};
Eratosthenes er((int)5e6);
long long A,P;
void solve()
{
	cin >> A >> P;
	bool prime = er.isp[P];
	if(prime)
	{
		if(A%P == 0) cout << 0 << "\n";
		else cout << 1 << "\n";
	}
	else cout << -1 << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	while(tt--) solve();
}
0