結果

問題 No.106 素数が嫌い!2
ユーザー yuppe19 😺
提出日時 2015-04-25 23:37:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 537 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 159,860 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-05 02:39:45
合計ジャッジ時間 2,611 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     int n, k; scanf("%d%d", &n, &k);
      |               ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<int> count(int n) {
    vector<int> res(n+1);
    fill(res.begin(), res.end(), 0);
    for(int i=2; i<=n; i++) {
        if(!res[i]) {
            for(int j=i; j<=n; j+=i) {
                res[j]++;
            }
        }
    }
    return res;
}

int main(void) {
    int n, k; scanf("%d%d", &n, &k);
    vector<int> counter = count(n);
    int res = 0;
    for(int i=0; i<counter.size(); i++) {
        if(counter[i] >= k) { res++; }
    }
    printf("%d\n", res);
    return 0;
}
0