結果
問題 | No.2751 429-like Number |
ユーザー |
|
提出日時 | 2024-05-10 22:41:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,935 ms / 4,000 ms |
コード長 | 2,773 bytes |
コンパイル時間 | 3,023 ms |
コンパイル使用メモリ | 255,432 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-20 06:36:58 |
合計ジャッジ時間 | 8,495 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;using ll = long long;long long multiply(long long a, long long b, long long m) {return static_cast<__int128>(a) * b % m;}long long power(long long a, long long e, long long m) {long long res = 1 % m;while (e > 0) {if (e % 2 == 1)res = multiply(res, a, m);a = multiply(a, a, m);e /= 2;}return res;}bool isPrime(long long n) {if (n < 2)return false;static constexpr int A[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};int s = __builtin_ctzll(n - 1);long long d = (n - 1) >> s;for (auto a : A) {if (a == n)return true;long long x = power(a, d, n);if (x == 1 || x == n - 1)continue;bool ok = false;for (int i = 0; i < s - 1; ++i) {x = multiply(x, x, n);if (x == n - 1) {ok = true;break;}}if (!ok)return false;}return true;}std::vector<long long> factorize(long long n) {std::vector<long long> p;std::function<void(long long)> f = [&](long long n) {if (n <= 10000) {for (int i = 2; i * i <= n; ++i)for (; n % i == 0; n /= i)p.push_back(i);if (n > 1)p.push_back(n);return;}if (isPrime(n)) {p.push_back(n);return;}auto g = [&](long long x) {return (multiply(x, x, n) + 1) % n;};long long x0 = 2;while (true) {long long x = x0;long long y = x0;long long d = 1;long long power = 1, lam = 0;long long v = 1;while (d == 1) {y = g(y);++lam;v = multiply(v, std::abs(x - y), n);if (lam % 127 == 0) {d = std::gcd(v, n);v = 1;}if (power == lam) {x = y;power *= 2;lam = 0;d = std::gcd(v, n);v = 1;}}if (d != n) {f(d);f(n / d);return;}++x0;}};f(n);std::sort(p.begin(), p.end());return p;}void solve() {ll n;cin >> n;auto fs = factorize(n);if ((int)fs.size() == 3) puts("Yes");else puts("No");}int main() {int t;cin >> t;while (t--) solve();return 0;}