結果
問題 | No.1113 二つの整数 / Two Integers |
ユーザー |
![]() |
提出日時 | 2020-10-13 01:16:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 2,616 bytes |
コンパイル時間 | 2,331 ms |
コンパイル使用メモリ | 211,280 KB |
最終ジャッジ日時 | 2025-01-15 06:58:35 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#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;}