結果

問題 No.144 エラトステネスのざる
ユーザー mencotton
提出日時 2020-11-02 16:26:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 78,852 KB
実行使用メモリ 7,464 KB
最終ジャッジ日時 2024-07-22 06:21:23
合計ジャッジ時間 1,711 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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