結果

問題 No.1140 EXPotentiaLLL!
ユーザー wunderkammer2wunderkammer2
提出日時 2020-08-01 10:01:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,335 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 105,592 KB
実行使用メモリ 42,268 KB
最終ジャッジ日時 2023-09-22 01:21:06
合計ジャッジ時間 12,467 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 875 ms
42,184 KB
testcase_01 AC 876 ms
41,900 KB
testcase_02 AC 923 ms
42,156 KB
testcase_03 AC 732 ms
42,108 KB
testcase_04 AC 577 ms
42,060 KB
testcase_05 AC 896 ms
42,012 KB
testcase_06 WA -
testcase_07 AC 914 ms
42,088 KB
testcase_08 AC 82 ms
41,992 KB
testcase_09 AC 83 ms
41,992 KB
testcase_10 AC 82 ms
41,912 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム(標準入力変更用)
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vll v;

template<typename T>
vector<T> smallest_prime_factors(T n)
{
    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;

    for (T i = 2; i * i <= n; i++)
    {
        // 素数だったら
        if (spf[i] == i)
        {
            for (T j = i * i; j <= n; j += i)
            {
                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) spf[j] = i;
            }
        }
    }

    return spf;
}

bool isPrime(ll x)
{
    return v[x] == x;
}

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    v = smallest_prime_factors(5 * 1000000LL);

    int T;
    in(T);

    rep(i, T)
    {
        ll A, P;
        in2(A, P);

        if (isPrime(P))
        {
            if (A % P == 0)
            {
                outl(0);
            }
            else
            {
                outl(1);
            }
        }
        else
        {
            outl(-1);
        }
    }

    return 0;
}
0