結果

問題 No.36 素数が嫌い!
ユーザー izryt(趣味)izryt(趣味)
提出日時 2016-01-14 03:04:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 708 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 158,044 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-09-19 19:00:30
合計ジャッジ時間 4,582 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 62 ms
13,056 KB
testcase_02 AC 4 ms
13,056 KB
testcase_03 AC 4 ms
13,056 KB
testcase_04 WA -
testcase_05 AC 6 ms
12,928 KB
testcase_06 AC 5 ms
13,184 KB
testcase_07 AC 5 ms
13,184 KB
testcase_08 AC 6 ms
13,056 KB
testcase_09 AC 5 ms
13,184 KB
testcase_10 AC 4 ms
13,076 KB
testcase_11 AC 54 ms
13,184 KB
testcase_12 AC 177 ms
13,184 KB
testcase_13 WA -
testcase_14 AC 46 ms
12,932 KB
testcase_15 AC 4 ms
13,056 KB
testcase_16 AC 4 ms
13,116 KB
testcase_17 AC 4 ms
13,184 KB
testcase_18 AC 3 ms
13,120 KB
testcase_19 AC 30 ms
13,056 KB
testcase_20 RE -
testcase_21 AC 60 ms
13,012 KB
testcase_22 AC 61 ms
13,056 KB
testcase_23 AC 33 ms
12,928 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 131 ms
13,056 KB
testcase_27 AC 147 ms
13,056 KB
testcase_28 AC 129 ms
12,928 KB
testcase_29 AC 168 ms
12,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool p[10000001];

ll n;

void sieve()
{
    for (ll i = 2; i * i <= n; ++i) {
        if (p[i]) for (ll j = i + i; j * j <= n; j += i) p[j] = false;
    }
}

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

int main()
{
    cin >> n;

    memset(p, true, sizeof(p));
    sieve();

    if (n == 1 || is_prime(n)) {
        cout << "NO" << endl;
        return 0;
    }

    for (ll i = 2; i * i <= n; ++i) if (n % i == 0 && (!p[i] || (((n / i) * (n / i)) <= n ? p[n / i] : !is_prime(n / i)))) {
        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;
}
0