結果

問題 No.144 エラトステネスのざる
ユーザー tsunabittsunabit
提出日時 2020-03-06 18:34:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 7,291 ms
コンパイル使用メモリ 74,924 KB
実行使用メモリ 45,824 KB
最終ジャッジ日時 2024-04-22 04:03:24
合計ジャッジ時間 7,664 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
41,748 KB
testcase_01 AC 146 ms
41,792 KB
testcase_02 AC 146 ms
41,452 KB
testcase_03 AC 144 ms
41,680 KB
testcase_04 AC 146 ms
41,508 KB
testcase_05 AC 145 ms
41,716 KB
testcase_06 AC 146 ms
41,996 KB
testcase_07 AC 141 ms
41,256 KB
testcase_08 AC 146 ms
41,728 KB
testcase_09 AC 146 ms
41,852 KB
testcase_10 AC 147 ms
41,336 KB
testcase_11 AC 147 ms
41,628 KB
testcase_12 AC 146 ms
41,856 KB
testcase_13 AC 210 ms
45,676 KB
testcase_14 AC 208 ms
45,492 KB
testcase_15 AC 209 ms
45,680 KB
testcase_16 AC 205 ms
45,368 KB
testcase_17 AC 206 ms
45,824 KB
testcase_18 AC 213 ms
45,584 KB
testcase_19 AC 202 ms
45,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No144 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double p = sc.nextDouble();
		int[] a = new int[n+1];
		
		for (int i = 2; i <= n; i++) {
			for (int j = i * 2; j <= n; j += i) {
				a[j]++;
			}
		}
		double t = 0;
		for(int i = 2; i <= n; i++) {
			t += Math.pow(1-p, a[i]);
		}
		System.out.println(t);
    }
}
0