結果

問題 No.144 エラトステネスのざる
ユーザー elphe
提出日時 2024-11-21 14:43:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 77,144 KB
最終ジャッジ日時 2025-02-25 05:47:04
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>

using namespace std;

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

	uint32_t N, i, j;
	double p;
	cin >> N >> p;

	vector<double> dp(N + 1, 1);
	double ans = 0;
	dp[0] = dp[1] = 1;
	for (i = 2; i <= N; ++i)
	{
		ans += dp[i];
		for (j = i * 2; j <= N; j += i)
			dp[j] *= 1 - p;
	}

	cout << fixed << setprecision(10) << ans << '\n';
	return 0;
}
0