結果

問題 No.144 エラトステネスのざる
ユーザー data9824
提出日時 2015-05-26 22:03:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 71,496 KB
実行使用メモリ 11,204 KB
最終ジャッジ日時 2024-07-06 09:10:51
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main() {
	int n;
	double p;
	cin >> n >> p;
	vector<double> pPrime(n + 1, 1.0);
	pPrime[0] = 0.0;
	pPrime[1] = 0.0;
	for (int i = 2; i <= n; ++i) {
		for (int k = i * 2; k <= n; k += i) {
			pPrime[k] *= 1.0 - p;
		}
	}
	sort(pPrime.begin(), pPrime.end());
	double result = accumulate(pPrime.begin(), pPrime.end(), 0.0);
	cout << setprecision(7) << result << endl;
	return 0;
}
0