結果

問題 No.1140 EXPotentiaLLL!
ユーザー Plan8Plan8
提出日時 2020-07-31 21:51:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 3,233 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 201,056 KB
実行使用メモリ 42,276 KB
最終ジャッジ日時 2023-09-20 22:56:44
合計ジャッジ時間 7,165 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
42,136 KB
testcase_01 AC 305 ms
42,016 KB
testcase_02 AC 320 ms
42,040 KB
testcase_03 AC 281 ms
42,264 KB
testcase_04 AC 242 ms
42,152 KB
testcase_05 AC 311 ms
42,112 KB
testcase_06 AC 296 ms
42,184 KB
testcase_07 AC 337 ms
42,136 KB
testcase_08 AC 124 ms
42,032 KB
testcase_09 AC 128 ms
42,196 KB
testcase_10 AC 122 ms
42,276 KB
testcase_11 AC 113 ms
42,108 KB
testcase_12 AC 118 ms
41,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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; }

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    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;
        if(x < 0) x += MOD;
    	return *this;
    }
    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 pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int N = 10000000;
vector<int> prime(10000001, 1);

void Main(){
    ll a,p; cin >> a >> p;
    if(prime[p] == 0){
        cout << -1 << en;
        return;
    }

    MOD = p;
    a %= p;

    if(p == 2){
        cout << (a*a)%p << en;
        return;
    }

    cout << (a>0 ? 1 : 0) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; cin>>t;

    prime[0] = 0; prime[1] = 0;
    for(int i=2; i<sqrt(N)+1; i++){
        if(prime[i] == 0) continue;
        for(int j=i*i; j<=N; j+=i) prime[j] = 0;
    }

    REP(_,t) Main();
    return 0;
}
0