結果

問題 No.144 エラトステネスのざる
コンテスト
ユーザー tonyu0
提出日時 2019-06-05 00:45:00
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 484 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 804 ms
コンパイル使用メモリ 108,344 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2026-04-06 23:07:40
合計ジャッジ時間 1,995 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

int m[1000010];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;
    double p,ans = 0.0;
    cin >> N >> p;
    for(int i = 2; i <= N; ++i){
        for(int j = i*2; j <= N; j += i) ++m[j];
        ans += pow(1-p,m[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
0