結果

問題 No.144 エラトステネスのざる
ユーザー Lepton_sLepton_s
提出日時 2015-02-11 00:08:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 380 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 52,172 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2023-09-05 23:06:16
合計ジャッジ時間 1,651 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,632 KB
testcase_01 AC 2 ms
5,560 KB
testcase_02 AC 2 ms
5,560 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
5,588 KB
testcase_07 AC 2 ms
5,568 KB
testcase_08 AC 2 ms
5,692 KB
testcase_09 AC 2 ms
5,584 KB
testcase_10 AC 2 ms
5,572 KB
testcase_11 AC 2 ms
5,620 KB
testcase_12 AC 2 ms
5,728 KB
testcase_13 AC 33 ms
15,224 KB
testcase_14 AC 34 ms
15,380 KB
testcase_15 AC 82 ms
15,280 KB
testcase_16 AC 33 ms
15,220 KB
testcase_17 AC 34 ms
15,224 KB
testcase_18 AC 33 ms
15,236 KB
testcase_19 AC 34 ms
15,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
#define N 1000100
int p[N];
double r[N];

int main(){
	int n;
	double q;
	cin>>n>>q;
	for(int i = 2; i <= n/2; i++)
		for(int j = i*2; j <= n; j+=i)
			p[j]++;
	r[0] = 1.0;
	for(int i = 1; i <= n; i++) r[i] = r[i-1]*(1.0-q);
	double res = 0;
	for(int i = 2; i <= n; i++)
		res += r[p[i]];
	cout.precision(9);
	cout<<res<<endl;
	return 0;
}
0