結果

問題 No.36 素数が嫌い!
ユーザー MisterMister
提出日時 2020-04-10 19:36:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,678 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 80,992 KB
実行使用メモリ 10,316 KB
最終ジャッジ日時 2023-10-13 14:22:05
合計ジャッジ時間 4,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
9,720 KB
testcase_01 AC 63 ms
8,916 KB
testcase_02 AC 63 ms
9,956 KB
testcase_03 AC 63 ms
9,232 KB
testcase_04 WA -
testcase_05 AC 63 ms
10,240 KB
testcase_06 AC 63 ms
8,336 KB
testcase_07 AC 62 ms
8,476 KB
testcase_08 AC 63 ms
8,508 KB
testcase_09 AC 63 ms
8,848 KB
testcase_10 AC 63 ms
9,304 KB
testcase_11 AC 65 ms
8,712 KB
testcase_12 AC 69 ms
8,964 KB
testcase_13 WA -
testcase_14 AC 63 ms
8,900 KB
testcase_15 AC 63 ms
8,440 KB
testcase_16 AC 63 ms
10,316 KB
testcase_17 AC 63 ms
9,792 KB
testcase_18 AC 63 ms
9,164 KB
testcase_19 AC 63 ms
9,196 KB
testcase_20 AC 63 ms
8,448 KB
testcase_21 AC 63 ms
9,628 KB
testcase_22 AC 63 ms
10,192 KB
testcase_23 AC 62 ms
8,736 KB
testcase_24 AC 64 ms
9,444 KB
testcase_25 AC 64 ms
9,632 KB
testcase_26 AC 65 ms
9,036 KB
testcase_27 AC 63 ms
8,920 KB
testcase_28 AC 66 ms
9,796 KB
testcase_29 AC 63 ms
9,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

struct Prime {
    int max_n;
    std::vector<int> primes;
    std::vector<bool> isp;

    explicit Prime(int max_n)
        : max_n(max_n), isp(max_n + 1, true) {
        isp[0] = isp[1] = false;
        for (int i = 2; i * i <= max_n; ++i) {
            if (isp[i]) {
                for (int j = i; i * j <= max_n; ++j) {
                    isp[i * j] = false;
                }
            }
        }

        for (int p = 2; p <= max_n; ++p) {
            if (isp[p]) primes.push_back(p);
        }
    }

    template <class T>
    bool isprime(T n) const {
        if (n <= max_n) return isp[n];
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p == 0) return false;
        }
        return true;
    }

    template <class T>
    std::vector<std::pair<T, int>> factorize(T n) const {
        std::vector<std::pair<T, int>> facts;
        for (T p : primes) {
            if (p * p > n) break;
            if (n % p != 0) continue;
            int exp = 0;
            while (n % p == 0) {
                n /= p;
                ++exp;
            }
            facts.emplace_back(p, exp);
        }
        if (n > 1) {
            facts.emplace_back(n, 1);
        }
        return facts;
    }
};

using lint = long long;

const Prime P(10000000);

void solve() {
    lint n;
    std::cin >> n;

    auto ps = P.factorize(n);

    bool ans = ps.size() > 2;
    for (auto& p : ps) {
        if (p.second > 1) ans = true;
    }

    std::cout << (ans ? "YES" : "NO") << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0