結果

問題 No.144 エラトステネスのざる
ユーザー bal4ubal4u
提出日時 2019-07-11 22:31:44
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 30,480 KB
実行使用メモリ 6,160 KB
最終ジャッジ日時 2023-08-08 11:22:15
合計ジャッジ時間 2,793 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 28 ms
5,688 KB
testcase_14 AC 74 ms
6,072 KB
testcase_15 AC 83 ms
6,044 KB
testcase_16 AC 79 ms
6,156 KB
testcase_17 AC 78 ms
6,160 KB
testcase_18 AC 80 ms
6,100 KB
testcase_19 AC 29 ms
5,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.144 エラトステネスのざる
// 2019.7.11 bal4u

#include <stdio.h>
#include <math.h>

#define EQ(a, b) (fabs((a)-(b)) < 1e-8)

int f[1000005];
int main()
{
	int i, j, n, N;
	double p, ans;
	
	scanf("%d%lf", &N, &p); n = N >> 1;
	for (i = 2; i <= n; i++) for (j = i << 1; j <= N; j += i) f[j]++;
	
	if (EQ(p, 0)) ans = N-1;
	else if (EQ(p, 1)) while (N > 1) ans += (f[N--] == 0);
	else {
		ans = 0;
		while (N > 1) ans += pow(1-p, f[N--]);
	}
	printf("%.10lf\n", ans);
	return 0;
}
0