結果

問題 No.1140 EXPotentiaLLL!
ユーザー abc3
提出日時 2020-08-01 16:04:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,255 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 169,352 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 02:45:30
合計ジャッジ時間 13,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<bool> prime(5000005,true);
void eratosthenes(){
  prime[0]=false;prime[1]=false;
  for(int i=2;i*i<=5000005;i++){
    for(int j=2;j<=5000005/i;j++){
      prime[i*j]=false;
    }
  }
}
int main() {
  int T;
  cin>>T;
  eratosthenes();
  for(int i=0;i<T;i++){
    int64_t A,P;
    cin>>A>>P;
    if(prime[P]){
      if(__gcd(A,P)==1){cout<<1<<endl;}
      else{cout<<0<<endl;}
    }
    else{cout<<-1<<endl;}
  }
  return 0;
}
0