結果

問題 No.36 素数が嫌い!
ユーザー fushime2
提出日時 2017-01-09 14:23:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 205 ms / 5,000 ms
コード長 839 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 63,320 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 00:53:02
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

bool is_prime(ll x) {
    for (ll i = 2; i*i <= x; ++i) {
        if (x%i == 0) return false;
    }
    return x != 1;
}

bool is_ok(ll x) {
    if (x <= 2) return false;
    if (is_prime(x)) return false;

    vector<ll> divs = divisor(x);

    for (auto& d : divs) {
        if (d == 1 || d == x || is_prime(d)) continue;
        return true;
    }
    return false;
}

int main(void) {
    ll x;
    cin >> x;

    cout << (is_ok(x) ? "YES" : "NO") << endl;

    return 0;
}
0