結果

問題 No.144 エラトステネスのざる
ユーザー finefine
提出日時 2016-06-05 19:33:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 162,948 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-19 08:22:17
合計ジャッジ時間 2,624 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 37 ms
11,596 KB
testcase_14 AC 35 ms
11,504 KB
testcase_15 AC 35 ms
11,520 KB
testcase_16 AC 36 ms
11,652 KB
testcase_17 AC 36 ms
11,520 KB
testcase_18 AC 39 ms
11,776 KB
testcase_19 AC 36 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000000;

double dp[MAX_N + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    double p;
    cin >> n >> p;
    p = 1 - p;
    fill(dp + 2, dp + n + 1, 1.0);
    for (int i = 2; i <= n / 2; i++) {
        for (int j = 2; i * j <= n; j++) {
            dp[i * j] *= p;
        }
    }
    double ans = 0.0;
    for (int i = 2; i <= n; i++) ans += dp[i];
    printf("%.10lf\n", ans);
    return 0;
}
0