結果

問題 No.144 エラトステネスのざる
ユーザー Pachicobue
提出日時 2018-12-19 21:05:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 79,336 KB
最終ジャッジ日時 2025-01-06 19:40:07
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
using ld = long double;
int main()
{
    int N;
    ld P;
    std::cin >> N >> P;
    std::vector<ld> p(N + 1, 1);
    for (int i = 1; i <= N; i++) { p[i] = (1 - P) * p[i - 1]; }
    std::vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; i++) {
        for (int j = 2; i * j <= N; j++) { cnt[i * j]++; }
    }
    ld ans = 0;
    for (int i = 2; i <= N; i++) { ans += p[cnt[i]]; }
    std::cout << std::fixed << std::setprecision(15) << ans << std::endl;
    return 0;
}
0