結果

問題 No.144 エラトステネスのざる
ユーザー furafyfurafy
提出日時 2015-03-08 20:04:36
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 24,884 KB
実行使用メモリ 17,460 KB
最終ジャッジ日時 2023-09-06 22:10:32
合計ジャッジ時間 1,282 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 40 ms
17,400 KB
testcase_14 AC 40 ms
17,448 KB
testcase_15 AC 40 ms
17,460 KB
testcase_16 AC 41 ms
17,452 KB
testcase_17 AC 40 ms
17,444 KB
testcase_18 AC 42 ms
17,444 KB
testcase_19 AC 39 ms
17,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int n, x, i;
	double p, mean = 0;
	double *list_of_koho;
	double *list_of_sosu;

	scanf("%d %lf", &n, &p);
	list_of_koho = (double *)malloc( sizeof( double ) * (n+1) );
	list_of_sosu = (double *)malloc( sizeof( double ) * (n+1) );
	for (i = 2; i <= n; i++) {
		list_of_koho[i] = 1;
		list_of_sosu[i] = 0;
	}
	for (x = 2; x <= n; x++) {
		list_of_sosu[x] = list_of_koho[x];
		list_of_koho[x] = 0;
		for (i = 2; x*i <= n; i++)
			list_of_koho[x*i] -= list_of_koho[x*i] * p;
	}
	for (i = 2; i <= n; i++) {
		mean += list_of_sosu[i];
	}
	printf("%.10f\n", mean);

	return 0;
}
0