結果

問題 No.144 エラトステネスのざる
ユーザー あおこうあおこう
提出日時 2023-07-17 12:48:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,119 bytes
コンパイル時間 2,945 ms
コンパイル使用メモリ 201,340 KB
実行使用メモリ 19,460 KB
最終ジャッジ日時 2023-10-18 00:22:39
合計ジャッジ時間 3,543 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 90 ms
19,460 KB
testcase_14 AC 96 ms
19,460 KB
testcase_15 WA -
testcase_16 AC 88 ms
19,460 KB
testcase_17 AC 94 ms
19,460 KB
testcase_18 AC 85 ms
19,460 KB
testcase_19 AC 89 ms
19,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, r) for(int i = 0; i < (r); ++i)
#define reps(i, s, r) for(int i = (s); i < (r); ++i)
#define fore(i, m2) for(auto &i : m2)
#define vi vector<int>
#define vl vector<ll>
#define pl pair<ll, ll>
#define all(i) (i).begin(), (i).end()
#define fs first
#define sc second

template <class T> bool chmin(T &i, T b) {
    if(i > b) {
        i = b;
        return true;
    }
    return false;
}
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll INF = LONG_LONG_MAX / 3;
const ll MOD = 1'000'000'007;
const ll MAX = 1e6 + 5;

ld IsPrime[MAX];

void solve(int max, ld p) {

    IsPrime[0] = 0;
    IsPrime[1] = 0;

    for(int i = 2; i * 2 <= max; ++i)
        for(int j = 2; i * j <= max; ++j)
            IsPrime[i * j] = IsPrime[i * j] * (1 - p);
}

int main() {

    ll n;
    ld p;
    cin >> n >> p;

    rep(i, n + 1) IsPrime[i] = 1;
    solve(n, p);

    ld sum = 0;
    rep(i, n + 1) sum += IsPrime[i];

    cout << sum << endl;
}
0