結果

問題 No.144 エラトステネスのざる
ユーザー krotonkroton
提出日時 2015-02-12 06:22:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 347 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 143,556 KB
実行使用メモリ 11,468 KB
最終ジャッジ日時 2023-09-05 23:54:11
合計ジャッジ時間 2,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,288 KB
testcase_01 AC 5 ms
11,344 KB
testcase_02 AC 5 ms
11,468 KB
testcase_03 AC 5 ms
11,412 KB
testcase_04 AC 5 ms
11,392 KB
testcase_05 AC 5 ms
11,332 KB
testcase_06 AC 5 ms
11,368 KB
testcase_07 AC 5 ms
11,344 KB
testcase_08 AC 5 ms
11,288 KB
testcase_09 AC 5 ms
11,368 KB
testcase_10 AC 4 ms
11,304 KB
testcase_11 AC 5 ms
11,344 KB
testcase_12 AC 5 ms
11,368 KB
testcase_13 AC 46 ms
11,348 KB
testcase_14 AC 46 ms
11,332 KB
testcase_15 AC 46 ms
11,460 KB
testcase_16 AC 46 ms
11,292 KB
testcase_17 AC 44 ms
11,428 KB
testcase_18 AC 49 ms
11,332 KB
testcase_19 AC 46 ms
11,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

double safe[1000010];

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

	fill(begin(safe), end(safe), 1);

	for(int d=2;d<=N;d++)
		for(int n=2*d;n<=N;n+=d)
			safe[n] *= 1 - p;

	double res = 0;
	for(int n=2;n<=N;n++)
		res += safe[n];

	printf("%.10f\n", res);
	return 0;
}
0