結果

問題 No.144 エラトステネスのざる
ユーザー chiho_miyako
提出日時 2015-04-17 13:23:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 74,380 KB
実行使用メモリ 60,736 KB
最終ジャッジ日時 2024-07-04 15:24:05
合計ジャッジ時間 6,928 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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