結果

問題 No.1140 EXPotentiaLLL!
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-01 00:07:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 2,221 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 88,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 03:50:48
合計ジャッジ時間 10,061 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 814 ms
4,380 KB
testcase_01 AC 812 ms
4,380 KB
testcase_02 AC 815 ms
4,380 KB
testcase_03 AC 639 ms
4,380 KB
testcase_04 AC 487 ms
4,376 KB
testcase_05 AC 774 ms
4,376 KB
testcase_06 AC 752 ms
4,376 KB
testcase_07 AC 832 ms
4,380 KB
testcase_08 AC 24 ms
4,376 KB
testcase_09 AC 24 ms
4,380 KB
testcase_10 AC 24 ms
4,380 KB
testcase_11 AC 24 ms
4,380 KB
testcase_12 AC 24 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int MOD = 1000000007;
struct mint {
    int64 x;
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};
vector<bool> isPrime(6*1000000, true);

void primes(const int64 _max, vector<bool>& isPrime) {
    isPrime[0] = isPrime[1] = false;
    for (int64 i=4; i<=_max; i+=2) isPrime[i] = false;
    for (int64 i=3; i<=_max; i+=2) {
        if (!isPrime[i]) continue;
        for (int64 j=i*i; j<=_max; j+=i) {
            isPrime[j] = false;
        }
    }
}

void solve() {
    int64 a,p;
    cin >> a >> p;
    MOD = p;
    if (isPrime[p]) {
        cout << (a%p!=0) << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    int t;
    cin >> t;
    primes(5*1000000, isPrime);
    for (int i=0; i<t; i++) solve();
}
0