結果

問題 No.1113 二つの整数 / Two Integers
ユーザー kyo1kyo1
提出日時 2020-10-13 01:16:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 2,616 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 216,508 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 23:52:59
合計ジャッジ時間 3,630 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

class MillerRabin {
 public:
  template <typename T>
  static bool is_prime(T n) {
    n = abs(n);
    if (n == 2) return true;
    if (n == 1 || (n & 1) == 0) return false;
    T d = n - 1;
    while ((d & 1) == 0) {
      d /= 2;
    }
    for (T a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}) {
      if (n == a) return true;
      T t = d, y = pow(a, t, n);
      while (t != n - 1 && y != 1 && y != n - 1) {
        y = pow(y, 2, n);
        t *= 2;
      }
      if (y != n - 1 && (t & 1) == 0) return false;
    }
    return true;
  }
};

class PollardRho {
 private:
  template <typename T>
  static T f(T x, T c, T mod) {
    return (pow(x, 2, mod) + c) % mod;
  }

  template <typename T>
  static T rho(T n) {
    if (n == 1 || MillerRabin::is_prime(n)) return n;
    if ((n & 1) == 0) return 2;
    T x = 2, y = 2, d = 1, c = 1;
    while (x == y) {
      do {
        x = f(x, c, n);
        y = f(f(y, c, n), c, n);
        d = std::gcd(abs(x - y), n);
      } while (std::gcd(abs(x - y), n) == 1);
      c++;
    }
    return d;
  }

 public:
  template <typename T>
  static std::vector<T> factor(T n) {
    std::vector<T> res;
    std::queue<T> que;
    que.push(n);
    while (!que.empty()) {
      T x = que.front();
      que.pop();
      if (x == 0 || x == 1) continue;
      if (MillerRabin::is_prime(x)) {
        res.emplace_back(x);
      } else {
        T d = rho(x);
        que.push(d), que.push(x / d);
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t A, B;
  cin >> A >> B;
  auto g = gcd(A, B);
  auto primes = PollardRho::factor(g);
  map<int, int> mp;
  for (auto p : primes) {
    mp[p]++;
  }
  int64_t x = 1;
  for (const auto& [key, value] : mp) {
    x *= value + 1;
  }
  if (x % 2 == 0) {
    cout << "Even" << '\n';
  } else {
    cout << "Odd" << '\n';
  }
  return 0;
}
0