結果

問題 No.144 エラトステネスのざる
ユーザー GOTKAKO
提出日時 2025-07-23 09:12:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 412 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 195,260 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2025-07-23 09:12:40
合計ジャッジ時間 4,063 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    double p; cin >> p; p = 1-p;
    vector<double> P(N+1,1);
    P.at(2) = 1;
    double answer = 0;
    for(int i=2; i<=N; i++){
        answer += P.at(i);
        for(int k=i+i; k<=N; k+=i) P.at(k) *= p;
    }
    cout << fixed << setprecision(20) << answer << endl;
}
0