結果

問題 No.144 エラトステネスのざる
ユーザー MayimgMayimg
提出日時 2019-01-29 02:04:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 925 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 166,940 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-16 17:08:42
合計ジャッジ時間 8,989 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 915 ms
7,552 KB
testcase_14 AC 924 ms
7,680 KB
testcase_15 AC 919 ms
7,680 KB
testcase_16 AC 924 ms
7,680 KB
testcase_17 AC 920 ms
7,552 KB
testcase_18 AC 925 ms
7,680 KB
testcase_19 AC 911 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	double p;
	cin >> p;
	vector<int> a(n + 1);
	for (int i = 2; i <= n; i++) {
		int x = i;
		vector<int> b;
		for (int j = 2; j * j <= x; j++) {
			int c = 0;
			while (x % j == 0) {
				c++;
				x /= j;
			}
			if (c != 0) b.push_back(c);
		}
		if (x != 1) b.push_back(1);
		int cnt = 1;
		for (auto &j : b) {
			cnt *= j + 1;
		}
		a[i] = cnt;
	}
	double ans = 0;
	for (int i = 2; i <= n; i++) {
		ans += pow(1.0 - p, a[i] - 2);
	}
	cout << setprecision(20) << fixed << ans << '\n';
	return 0;
}
0