結果

問題 No.144 エラトステネスのざる
ユーザー samplelpmas
提出日時 2017-05-12 11:02:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 2,660 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 49,528 KB
最終ジャッジ日時 2024-09-15 10:41:54
合計ジャッジ時間 7,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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];
        double answer = 0;

        for (int i = 2; i <= N; i++) {

            answer += Math.pow(1 - P, primes[i]);

            for (int j = i * 2; j <= N; j += i) {
                primes[j]++;
            }

        }

        System.out.println(answer);

    }

}
0