結果

問題 No.1140 EXPotentiaLLL!
ユーザー yutasyutas
提出日時 2020-07-31 22:06:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,189 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 167,616 KB
実行使用メモリ 13,512 KB
最終ジャッジ日時 2023-09-20 23:31:02
合計ジャッジ時間 10,637 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 847 ms
5,604 KB
testcase_01 AC 812 ms
5,528 KB
testcase_02 AC 841 ms
5,528 KB
testcase_03 AC 759 ms
13,512 KB
testcase_04 AC 583 ms
13,244 KB
testcase_05 AC 931 ms
13,232 KB
testcase_06 AC 862 ms
13,240 KB
testcase_07 AC 1,189 ms
13,200 KB
testcase_08 AC 2 ms
5,524 KB
testcase_09 AC 2 ms
5,668 KB
testcase_10 AC 2 ms
5,516 KB
testcase_11 AC 2 ms
5,484 KB
testcase_12 AC 2 ms
5,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

vector <int> Prime;
bool visited[int(5e6+5)], res[int(5e6+5)];

bool isPrime(int P){
  if (visited[P]) return res[P];
  visited[P] = true;

  if (P == 1) return false;

  for (int i = 0; i < Prime.size(); i++){
    if (P % Prime[i] == 0){
      return res[P] = false;
    } 
  }
  return res[P] = true;
}

ll A, P;

int Solve(){
  scanf("%lld%lld", &A, &P);

  if (!isPrime(P)){
    cout << -1 << endl;
  }else if (A % P == 0){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

int main(){
  Prime.push_back(2);
  visited[2] = true; res[2] = true;
  for (int i = 3; i * i <= int(5e6); i+=2){
    visited[i] = true;
    res[i] = true;
    for (int j = 2; j * j <= i; j++){
      if (i % j == 0){
        res[i] = false; break;
      }
    }
    if (res[i]) Prime.push_back(i);   
  }

  int T; cin >> T;
  for (int i = 0; i < T; i++) Solve();


  return 0;
}
0