結果
| 問題 |
No.2751 429-like Number
|
| コンテスト | |
| ユーザー |
soto800
|
| 提出日時 | 2024-05-10 21:36:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 593 ms / 4,000 ms |
| コード長 | 5,069 bytes |
| コンパイル時間 | 2,090 ms |
| コンパイル使用メモリ | 204,748 KB |
| 最終ジャッジ日時 | 2025-02-21 12:24:20 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 22 |
ソースコード
#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;
}
soto800