結果

問題 No.36 素数が嫌い!
ユーザー izryt(趣味)izryt(趣味)
提出日時 2016-01-14 03:07:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,297 ms / 5,000 ms
コード長 666 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 144,600 KB
実行使用メモリ 13,368 KB
最終ジャッジ日時 2023-09-09 07:32:31
合計ジャッジ時間 15,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
13,056 KB
testcase_01 AC 76 ms
13,132 KB
testcase_02 AC 5 ms
13,068 KB
testcase_03 AC 6 ms
13,188 KB
testcase_04 AC 6 ms
13,092 KB
testcase_05 AC 8 ms
13,112 KB
testcase_06 AC 8 ms
13,084 KB
testcase_07 AC 6 ms
13,244 KB
testcase_08 AC 6 ms
13,092 KB
testcase_09 AC 6 ms
13,160 KB
testcase_10 AC 6 ms
13,172 KB
testcase_11 AC 58 ms
13,084 KB
testcase_12 AC 186 ms
13,136 KB
testcase_13 AC 3,297 ms
13,056 KB
testcase_14 AC 173 ms
13,064 KB
testcase_15 AC 6 ms
13,368 KB
testcase_16 AC 6 ms
13,116 KB
testcase_17 AC 6 ms
13,084 KB
testcase_18 AC 6 ms
13,068 KB
testcase_19 AC 29 ms
13,068 KB
testcase_20 AC 89 ms
13,168 KB
testcase_21 AC 63 ms
13,332 KB
testcase_22 AC 83 ms
13,300 KB
testcase_23 AC 36 ms
13,172 KB
testcase_24 AC 54 ms
13,092 KB
testcase_25 AC 38 ms
13,240 KB
testcase_26 AC 1,689 ms
13,084 KB
testcase_27 AC 2,618 ms
13,244 KB
testcase_28 AC 1,628 ms
13,100 KB
testcase_29 AC 3,096 ms
13,304 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 ((!p[i] || !is_prime(n/i)) && n % i == 0) {
        cout << "YES" << endl;
        return 0;
    }

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