結果

問題 No.144 エラトステネスのざる
ユーザー 37zigen37zigen
提出日時 2016-11-25 00:44:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 2,811 ms
コンパイル使用メモリ 75,892 KB
実行使用メモリ 49,600 KB
最終ジャッジ日時 2024-05-05 13:10:28
合計ジャッジ時間 6,426 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,848 KB
testcase_01 AC 135 ms
41,592 KB
testcase_02 AC 127 ms
41,644 KB
testcase_03 AC 123 ms
41,468 KB
testcase_04 AC 119 ms
41,572 KB
testcase_05 AC 109 ms
41,464 KB
testcase_06 AC 119 ms
41,592 KB
testcase_07 AC 105 ms
40,716 KB
testcase_08 AC 113 ms
40,652 KB
testcase_09 AC 124 ms
41,232 KB
testcase_10 AC 125 ms
41,456 KB
testcase_11 AC 123 ms
41,624 KB
testcase_12 AC 114 ms
41,128 KB
testcase_13 AC 181 ms
49,600 KB
testcase_14 AC 197 ms
49,176 KB
testcase_15 AC 187 ms
49,368 KB
testcase_16 AC 191 ms
49,600 KB
testcase_17 AC 184 ms
49,416 KB
testcase_18 AC 174 ms
49,144 KB
testcase_19 AC 168 ms
49,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class Q144 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double p = sc.nextDouble();
		double[] pro = new double[n + 1];
		for (int i = 2; i <= n; ++i) {
			pro[i] = 1;
		}
		for (int i = 2; i <= n; ++i) {
			for (int j = 2 * i; j <= n; j += i) {
				pro[j] = pro[j] * (1 - p);
			}
		} 
		double ans = 0;
		for (int i = 2; i <= n; ++i) {
			ans += pro[i];
		}
		System.out.println(ans);

	}
}
0