結果

問題 No.106 素数が嫌い!2
ユーザー sahiyasahiya
提出日時 2021-03-02 19:25:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,622 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 114,136 KB
実行使用メモリ 5,016 KB
最終ジャッジ日時 2023-07-26 14:51:59
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 3 ms
4,432 KB
testcase_09 AC 3 ms
4,480 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 2E+05;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

int N, K;

ll spf[MAX_N + 1]; //spf[i]はiの素因数のうち最小のものを示す

void smallest_prime_factor(ll n);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> K;
    smallest_prime_factor(N);

    int ans = 0;
    for (int i = 2; i <= N; i++) {
        // cout << "i = " << i << ", spf = " << spf[i] << "\n";
        if (spf[i] >= K)
            ans++;
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

//n以下のspfを求める
void smallest_prime_factor(ll n)
{
    for (ll i = 2; i <= n; i++) {
        if (spf[i] == 0) {
            for (ll j = i; j <= n; j += i) {
                spf[j]++;
            }
        }
    }
}
0