結果

問題 No.144 エラトステネスのざる
ユーザー bal4ubal4u
提出日時 2019-07-11 22:31:44
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 33,280 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-26 04:23:18
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 26 ms
5,760 KB
testcase_14 AC 45 ms
6,016 KB
testcase_15 AC 46 ms
6,144 KB
testcase_16 AC 46 ms
6,016 KB
testcase_17 AC 45 ms
6,016 KB
testcase_18 AC 51 ms
6,016 KB
testcase_19 AC 30 ms
5,888 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