結果

問題 No.144 エラトステネスのざる
ユーザー mencottonmencotton
提出日時 2020-11-02 16:26:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 78,608 KB
実行使用メモリ 7,152 KB
最終ジャッジ日時 2023-09-29 11:59:35
合計ジャッジ時間 1,703 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 30 ms
7,060 KB
testcase_14 AC 30 ms
7,152 KB
testcase_15 AC 30 ms
7,060 KB
testcase_16 AC 30 ms
7,088 KB
testcase_17 AC 29 ms
6,976 KB
testcase_18 AC 29 ms
7,152 KB
testcase_19 AC 29 ms
7,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
using ld = long double;

int main() {
    int n;
    ld p;
    cin >> n >> p;

    vector<int> count(n + 1);
    for (int i = 2; i <= n; i++) {
        for (int j = i * 2; j <= n; j += i)count[j]++;
    }

    vector<ld> v(1000, 1.0);
    for (int i = 1; i < 1000; i++)v[i] = v[i - 1] * (1.0 - p);

    ld ret = 0;
    for (int i = 2; i <= n; i++) {
        ret += v[count[i]];
    }

    cout << fixed << setprecision(20) << ret << endl;
    return 0;
}
0