結果

問題 No.144 エラトステネスのざる
ユーザー htensaihtensai
提出日時 2020-01-23 12:18:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 2,861 ms
コンパイル使用メモリ 72,528 KB
実行使用メモリ 60,088 KB
最終ジャッジ日時 2023-09-26 07:05:26
合計ジャッジ時間 7,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
55,936 KB
testcase_01 AC 148 ms
56,120 KB
testcase_02 AC 145 ms
55,872 KB
testcase_03 AC 150 ms
56,104 KB
testcase_04 AC 141 ms
56,128 KB
testcase_05 AC 152 ms
55,932 KB
testcase_06 AC 142 ms
55,636 KB
testcase_07 AC 165 ms
55,688 KB
testcase_08 AC 150 ms
55,984 KB
testcase_09 AC 149 ms
56,324 KB
testcase_10 AC 146 ms
54,272 KB
testcase_11 AC 146 ms
55,708 KB
testcase_12 AC 151 ms
56,088 KB
testcase_13 AC 224 ms
60,084 KB
testcase_14 AC 207 ms
60,088 KB
testcase_15 AC 210 ms
59,972 KB
testcase_16 AC 225 ms
58,240 KB
testcase_17 AC 219 ms
60,040 KB
testcase_18 AC 217 ms
59,776 KB
testcase_19 AC 200 ms
59,792 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();
        int[] arr = new int[n + 1];
        double ans = 0;
        for (int i = 2; i <= n; i++) {
            for (int j = 2; j * i <= n; j++) {
                arr[i * j]++;
            }
            if (arr[i] == 0) {
                ans++;
            } else {
                ans += Math.pow(1 - p, arr[i]);
            }
        }
        System.out.println(ans);
    }
}
0