結果

問題 No.144 エラトステネスのざる
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-17 13:23:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 3,561 ms
コンパイル使用メモリ 71,184 KB
実行使用メモリ 62,636 KB
最終ジャッジ日時 2023-09-17 21:29:37
合計ジャッジ時間 7,442 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
56,288 KB
testcase_01 AC 136 ms
56,352 KB
testcase_02 AC 136 ms
55,852 KB
testcase_03 AC 136 ms
56,028 KB
testcase_04 AC 134 ms
55,684 KB
testcase_05 AC 134 ms
55,984 KB
testcase_06 AC 135 ms
56,184 KB
testcase_07 AC 141 ms
56,052 KB
testcase_08 AC 136 ms
56,180 KB
testcase_09 AC 136 ms
56,712 KB
testcase_10 AC 136 ms
56,012 KB
testcase_11 AC 136 ms
56,008 KB
testcase_12 AC 137 ms
56,204 KB
testcase_13 AC 213 ms
62,404 KB
testcase_14 AC 206 ms
62,224 KB
testcase_15 AC 208 ms
62,532 KB
testcase_16 AC 214 ms
62,348 KB
testcase_17 AC 212 ms
62,616 KB
testcase_18 AC 209 ms
62,376 KB
testcase_19 AC 200 ms
62,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n=koko.nextInt();
        double p = koko.nextDouble();
        double[] r = new double[n+1];
        Arrays.fill(r,1);
        double count=0;
        for(int i=2; i<n+1; i++){
            count=count+r[i];
            for(int j=2; j<=n/i; j++){
                r[j*i]=r[j*i]*(1-p);
            }
        }
        System.out.println(count);
    }
}
0