結果

問題 No.1140 EXPotentiaLLL!
ユーザー magmag
提出日時 2020-08-05 11:17:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 851 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 169,424 KB
実行使用メモリ 23,292 KB
最終ジャッジ日時 2023-10-14 08:59:13
合計ジャッジ時間 12,136 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 831 ms
23,200 KB
testcase_01 AC 837 ms
23,100 KB
testcase_02 AC 851 ms
23,292 KB
testcase_03 AC 661 ms
23,204 KB
testcase_04 AC 513 ms
23,140 KB
testcase_05 AC 811 ms
23,256 KB
testcase_06 AC 757 ms
23,196 KB
testcase_07 AC 841 ms
23,288 KB
testcase_08 AC 36 ms
22,960 KB
testcase_09 AC 37 ms
23,068 KB
testcase_10 AC 37 ms
23,220 KB
testcase_11 AC 36 ms
23,244 KB
testcase_12 AC 37 ms
22,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
void in(){} template<typename Head,typename... Tail> void in(Head&& head,Tail&&... tail){cin>>head;in(forward<Tail>(tail)...);}
void out(){cout<<endl;} template<typename Head,typename... Tail> void out(Head&& head,Tail&&... tail){cout<<head<<" ";out(forward<Tail>(tail)...);}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int t;cin>>t;
  int n=5000000;
  //素数の個数
  vector<int> prime(n);
  //素数であるか
  vector<bool> is_prime(n+1,true);
  //bool is_prime[n+1];rep(i,n+1)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  int hoge=0;
  rep2(i,2,n+1){
    if(is_prime[i]){
      prime[hoge++]=i;
      for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }

  ll a,p;
  rep(i,t){
    in(a,p);
    //out(a,p);
    //そうでなければ − 1
    if(!is_prime[p]){
      cout<<-1<<endl;
    //P が素数であれば A^P!(mod P) 
    //Fermat の小定理とは p を素数、a を p の倍数でない任意の整数としたとき、 
    //a^(p−1)≡1(mod p) が成立する。
    }else if(a%p==0){
      cout<<0<<endl;
    }else{
      cout<<1<<endl;
    }
  }
}
0