結果

問題 No.1140 EXPotentiaLLL!
ユーザー DaYuanChiDaYuanChi
提出日時 2021-04-05 00:26:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 167,180 KB
実行使用メモリ 27,976 KB
最終ジャッジ日時 2024-12-29 10:39:40
合計ジャッジ時間 19,335 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = 5e6;
bool is_prime[N+5];
int d[N+5]; //d[i]=iの最小の素因数

int main(){
  for(int i = 0; i < N; i++) is_prime[i]=true; //エラトステネス
  for(int i = 2; i < N; i++){
    if(is_prime[i]) d[i] = i;
    for(int j = i + i; j < N; j += i){
      is_prime[j] = false;
      if(is_prime[i] && d[j]==0) d[j] = i;
    }
  }
  int t; cin >> t;
  for(int i = 0; i < t; i++){
    ll a; int p; cin >> a >> p;
    if(is_prime[p]){
      if(a%p!=0) cout << 1 << endl;
      else cout << 0 << endl;
    }
    else cout << -1 << endl;
  }
  return 0;
}
0