結果

問題 No.106 素数が嫌い!2
ユーザー finefine
提出日時 2016-03-15 19:06:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 654 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 159,484 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-08 13:23:19
合計ジャッジ時間 4,352 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 8 ms
11,136 KB
testcase_02 AC 8 ms
11,136 KB
testcase_03 WA -
testcase_04 AC 101 ms
11,136 KB
testcase_05 AC 264 ms
11,136 KB
testcase_06 AC 263 ms
11,136 KB
testcase_07 AC 264 ms
11,136 KB
testcase_08 AC 14 ms
11,136 KB
testcase_09 AC 14 ms
11,136 KB
testcase_10 AC 268 ms
11,136 KB
testcase_11 AC 86 ms
11,136 KB
testcase_12 AC 249 ms
11,136 KB
testcase_13 AC 8 ms
11,136 KB
testcase_14 AC 8 ms
11,136 KB
testcase_15 AC 8 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a[2000000] = {0},n,x,f;
    long long ans = 0;
    cin >> n >> x;
    for(int i = 2; i <= n; i += 2){
        a[i - 2] = 1;
    }
    for(int i = 2; i <= n; i++){
        if (a[i - 2] > 0) {
            if (a[i - 2] >= x) ans++;
            continue;
        }
        f = 0;
        for(int j = 3; j * j <= i; j += 2){
            if (i % j == 0) {
                f = 1;
                break;
            }
        }
        if (f == 0) {
            for(int k = i; k <= n; k += i) {
                a[k - 2]++;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
0