結果

問題 No.144 エラトステネスのざる
ユーザー kkslucy1kkslucy1
提出日時 2018-03-13 17:16:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 899 ms / 2,000 ms
コード長 566 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 148,992 KB
実行使用メモリ 11,492 KB
最終ジャッジ日時 2023-08-14 12:26:47
合計ジャッジ時間 8,516 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,336 KB
testcase_01 AC 6 ms
11,284 KB
testcase_02 AC 7 ms
11,320 KB
testcase_03 AC 7 ms
11,280 KB
testcase_04 AC 6 ms
11,440 KB
testcase_05 AC 6 ms
11,348 KB
testcase_06 AC 6 ms
11,336 KB
testcase_07 AC 6 ms
11,400 KB
testcase_08 AC 53 ms
11,424 KB
testcase_09 AC 7 ms
11,444 KB
testcase_10 AC 6 ms
11,348 KB
testcase_11 AC 7 ms
11,444 KB
testcase_12 AC 6 ms
11,372 KB
testcase_13 AC 843 ms
11,428 KB
testcase_14 AC 838 ms
11,276 KB
testcase_15 AC 899 ms
11,324 KB
testcase_16 AC 854 ms
11,296 KB
testcase_17 AC 851 ms
11,492 KB
testcase_18 AC 846 ms
11,372 KB
testcase_19 AC 840 ms
11,440 KB
権限があれば一括ダウンロードができます

ソースコード

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