結果

問題 No.144 エラトステネスのざる
ユーザー tentententen
提出日時 2020-10-14 12:00:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 71,444 KB
実行使用メモリ 62,452 KB
最終ジャッジ日時 2023-09-28 00:32:15
合計ジャッジ時間 6,823 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
55,720 KB
testcase_01 AC 141 ms
56,024 KB
testcase_02 AC 142 ms
55,884 KB
testcase_03 AC 145 ms
56,480 KB
testcase_04 AC 142 ms
56,072 KB
testcase_05 AC 141 ms
55,952 KB
testcase_06 AC 142 ms
56,036 KB
testcase_07 AC 143 ms
56,048 KB
testcase_08 AC 143 ms
56,040 KB
testcase_09 AC 143 ms
55,904 KB
testcase_10 AC 142 ms
55,612 KB
testcase_11 AC 141 ms
56,012 KB
testcase_12 AC 142 ms
55,872 KB
testcase_13 AC 196 ms
62,080 KB
testcase_14 AC 203 ms
61,884 KB
testcase_15 AC 202 ms
61,936 KB
testcase_16 AC 201 ms
62,228 KB
testcase_17 AC 203 ms
62,252 KB
testcase_18 AC 204 ms
62,452 KB
testcase_19 AC 198 ms
62,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	double p = sc.nextDouble();
    	double[] primes = new double[n + 1];
    	Arrays.fill(primes, 1.0);
    	double ans = 0;
    	for (int i = 2; i <= n; i++) {
    	    ans += primes[i];
    	    for (int j = 2; j * i <= n; j++) {
    	        primes[i * j] *= (1 - p);
    	    }
    	}
    	System.out.print(ans);
	}
}
0