結果

問題 No.2751 429-like Number
ユーザー V_MelvilleV_Melville
提出日時 2024-05-10 22:38:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,072 bytes
コンパイル時間 2,771 ms
コンパイル使用メモリ 256,204 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-10 22:38:55
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 34 ms
6,944 KB
testcase_10 AC 98 ms
6,940 KB
testcase_11 AC 176 ms
6,944 KB
testcase_12 AC 161 ms
6,940 KB
testcase_13 AC 286 ms
6,944 KB
testcase_14 AC 512 ms
6,940 KB
testcase_15 AC 58 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 136 ms
6,944 KB
testcase_19 AC 150 ms
6,940 KB
testcase_20 AC 139 ms
6,948 KB
testcase_21 AC 136 ms
6,940 KB
testcase_22 AC 135 ms
6,944 KB
testcase_23 AC 142 ms
6,944 KB
testcase_24 AC 138 ms
6,944 KB
testcase_25 AC 138 ms
6,940 KB
testcase_26 AC 137 ms
6,944 KB
testcase_27 AC 137 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

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 isPrime(ll n) {
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n%2 == 0) return false;
    vector<ll> a = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    int s = 0; ll d = n-1;
    while (d%2 == 0) {
        ++s;
        d >>= 1;
    }
    for (ll x : a) {
        if (x >= n) break;
        ll b = pow_mod<__int128_t>(x, d, n);
        if (b != 1) {
            bool ok = true;
            rep(i, s) {
                if (b == n-1) {
                    ok = false;
                    break;
                }
                b = __int128_t(b)*b%n;
            }
            if (ok) return false;
        }
    }
    return true;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    if (b == 0) return a;
    return gcd(b, a%b);
}

ll pollard(ll n) {
    if (n%2 == 0) return 2;
    if (isPrime(n)) return n;
    
    auto f = [&](ll x) -> ll { return (__int128_t(x)*x+1)%n; };
    
    ll step = 0;
    while (1) {
        ++step;
        ll x = step, y = f(x);
        while (1) {
            ll p = gcd(y-x+n, n);
            if (!p or p == n) break;
            if (p != 1) return p;
            x = f(x); y = f(f(y));
        }
    }
}

vector<ll> fatorList(ll n) {
    if (n == 1) return {};
    ll p = pollard(n);
    if (p == n) return {p};
    vector<ll> left = fatorList(p);
    vector<ll> right = fatorList(n/p);
    left.insert(left.end(), right.begin(), right.end());
    sort(left.begin(), left.end());
    return left;
}

void solve() {
    ll n;
    cin >> n;
    
    if (n == 1) {
        puts("No");
        return;
    }
    
    auto fs = fatorList(n);
    
    if ((int)fs.size() == 3) puts("Yes");
    else puts("No");
}

int main() {
    int t;
    cin >> t;
    
    while (t--) solve();
    
    return 0;
}
0