結果

問題 No.144 エラトステネスのざる
ユーザー kkslucy1
提出日時 2018-03-13 17:16:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 924 ms / 2,000 ms
コード長 566 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 163,164 KB
実行使用メモリ 11,604 KB
最終ジャッジ日時 2024-11-22 09:29:10
合計ジャッジ時間 8,508 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

double dp[1000001];

int main() {
	int n;
	cin >> n;
	double p;
	cin >> p;

	dp[0] = 1;
	for (int i = 1;i <= 1000000;i++) {
		dp[i] = (1 - p)*dp[i - 1];
	}
	
	double ans = 0;
	for (int i = 2;i <= n;i++) {
		int num = 1;
		int x = i;
		multiset<int> set;
		for (int j = 2;j*j <= x;j++) {
			while (x%j == 0&&j*j<=x) {
				x /= j;
				set.insert(j);
			}
		}
		set.insert(x);
		while (!set.empty()) {
			num *= set.erase(*set.begin()) + 1;
		}
		ans += dp[num - 2];
	}

	cout << setprecision(9)<<ans << endl;
	return 0;
}
0