結果

問題 No.1140 EXPotentiaLLL!
ユーザー niuezniuez
提出日時 2021-04-29 16:26:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,233 ms / 2,000 ms
コード長 2,124 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 166,832 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 01:11:22
合計ジャッジ時間 12,974 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,185 ms
4,380 KB
testcase_01 AC 1,233 ms
4,376 KB
testcase_02 AC 1,165 ms
4,380 KB
testcase_03 AC 865 ms
4,376 KB
testcase_04 AC 654 ms
4,380 KB
testcase_05 AC 1,047 ms
4,376 KB
testcase_06 AC 1,000 ms
4,380 KB
testcase_07 AC 1,183 ms
4,376 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 35 ms
4,380 KB
testcase_11 AC 34 ms
4,380 KB
testcase_12 AC 34 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
 
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
 
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
 
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
 
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }


int main() {
  int T;
  cin >> T;

  const i64 MAX = 5050505;
  
  std::bitset<MAX> prime;
  prime.flip();
  prime.reset(0);
  prime.reset(1);

  for(int i = 2; i < MAX; i++) {
    if(prime[i]) {
      for(int j = i + i; j < MAX; j += i) {
        prime.reset(j);
      }
    }
  }

  auto func = [&](i64 a, i64 p) {
    if(!prime.test(p)) return -1ll;
    if(a % p == 0) {
      return 0ll;
    }
    else {
      return 1ll;
    }
  };
    
  while(T--) {
    i64 a, p;
    cin >> a >> p;
    std::cout << func(a, p) << std::endl;
  }
}
0