結果

問題 No.2751 429-like Number
ユーザー soto800soto800
提出日時 2024-05-10 21:36:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 625 ms / 4,000 ms
コード長 5,069 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 210,584 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-10 21:36:53
合計ジャッジ時間 6,973 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 48 ms
6,944 KB
testcase_08 AC 63 ms
6,940 KB
testcase_09 AC 50 ms
6,944 KB
testcase_10 AC 112 ms
6,940 KB
testcase_11 AC 224 ms
6,940 KB
testcase_12 AC 200 ms
6,940 KB
testcase_13 AC 312 ms
6,940 KB
testcase_14 AC 625 ms
6,944 KB
testcase_15 AC 62 ms
6,944 KB
testcase_16 AC 110 ms
6,940 KB
testcase_17 AC 118 ms
6,944 KB
testcase_18 AC 180 ms
6,944 KB
testcase_19 AC 175 ms
6,940 KB
testcase_20 AC 183 ms
6,944 KB
testcase_21 AC 179 ms
6,940 KB
testcase_22 AC 180 ms
6,944 KB
testcase_23 AC 177 ms
6,944 KB
testcase_24 AC 180 ms
6,944 KB
testcase_25 AC 178 ms
6,944 KB
testcase_26 AC 184 ms
6,940 KB
testcase_27 AC 178 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//#include <atcoder/all>
using namespace std;

#define lli long long int
#define REP(i, s, n) for (lli i = s; i < n; i++)
#define INF (1LL << 62)
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) #VariableName
#define LOG1(x)                                                                \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << endl;
#define LOG2(x, y)                                                             \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << endl;
#define LOG3(x, y, z)                                                          \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << " " \
         << TO_STRING(z) << "=" << z << endl;
#define LOG4(w, x, y, z)                                                       \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z        \
         << endl;
#define LOG5(w, x, y, z, a)                                                    \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << endl;
#define LOG6(w, x, y, z, a, b)                                                 \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << " " << TO_STRING(b) << "=" << b        \
         << endl;

#define overload6(a, b, c, d, e, f, g, ...) g
#define LOG(...)                                                               \
  overload6(__VA_ARGS__, LOG6, LOG5, LOG4, LOG3, LOG2, LOG1)(__VA_ARGS__)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

mt19937 engine;
std::chrono::system_clock::time_point start, endTime;

#define DEBUG 0

// https://github.com/drken1215/algorithm/blob/master/MathNumberTheory/pollard_rho.cpp

// Miller-Rabin 素数判定法
template <class T> T pow_mod(T A, T N, T M) {
  T res = 1 % M;
  A %= M;
  while (N) {
    if (N & 1)
      res = (res * A) % M;
    A = (A * A) % M;
    N >>= 1;
  }
  return res;
}

bool is_prime(long long N) {
  if (N <= 1)
    return false;
  if (N == 2 || N == 3)
    return true;
  if (N % 2 == 0)
    return false;
  vector<long long> A = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  long long s = 0, d = N - 1;
  while (d % 2 == 0) {
    ++s;
    d >>= 1;
  }
  for (auto a : A) {
    if (a % N == 0)
      return true;
    long long t, x = pow_mod<__int128_t>(a, d, N);
    if (x != 1) {
      for (t = 0; t < s; ++t) {
        if (x == N - 1)
          break;
        x = __int128_t(x) * x % N;
      }
      if (t == s)
        return false;
    }
  }
  return true;
}

// Pollard のロー法
long long gcd(long long A, long long B) {
  A = abs(A), B = abs(B);
  if (B == 0)
    return A;
  else
    return gcd(B, A % B);
}

long long pollard(long long N) {
  if (N % 2 == 0)
    return 2;
  if (is_prime(N))
    return N;

  auto f = [&](long long x) -> long long {
    return (__int128_t(x) * x + 1) % N;
  };
  long long step = 0;
  while (true) {
    ++step;
    long long x = step, y = f(x);
    while (true) {
      long long p = gcd(y - x + N, N);
      if (p == 0 || p == N)
        break;
      if (p != 1)
        return p;
      x = f(x);
      y = f(f(y));
    }
  }
}

vector<long long> prime_factorize(long long N) {
  if (N == 1)
    return {};
  long long p = pollard(N);
  if (p == N)
    return {p};
  vector<long long> left = prime_factorize(p);
  vector<long long> right = prime_factorize(N / p);
  left.insert(left.end(), right.begin(), right.end());
  sort(left.begin(), left.end());
  return left;
}

void solve() {
  //  write your code here
  lli num;
  cin >> num;

  auto ans = prime_factorize(num);
  if (ans.size() == 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

// Generated by 2.13.0 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  // Failed to predict input format

  lli N = 1;
  cin >> N;
  while (N--)
    solve();

  return 0;
}
0