結果

問題 No.144 エラトステネスのざる
ユーザー kou6839kou6839
提出日時 2015-06-26 19:05:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 413 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 71,352 KB
実行使用メモリ 60,676 KB
最終ジャッジ日時 2023-09-22 00:46:59
合計ジャッジ時間 6,977 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
55,996 KB
testcase_01 AC 141 ms
56,360 KB
testcase_02 AC 140 ms
56,164 KB
testcase_03 AC 140 ms
55,924 KB
testcase_04 AC 143 ms
56,080 KB
testcase_05 AC 141 ms
55,992 KB
testcase_06 AC 140 ms
55,716 KB
testcase_07 AC 142 ms
56,336 KB
testcase_08 AC 140 ms
56,036 KB
testcase_09 AC 138 ms
56,448 KB
testcase_10 AC 142 ms
56,124 KB
testcase_11 AC 140 ms
56,204 KB
testcase_12 AC 141 ms
55,884 KB
testcase_13 AC 207 ms
58,312 KB
testcase_14 AC 205 ms
60,360 KB
testcase_15 AC 205 ms
60,676 KB
testcase_16 AC 208 ms
59,824 KB
testcase_17 AC 203 ms
60,360 KB
testcase_18 AC 213 ms
60,248 KB
testcase_19 AC 199 ms
60,288 KB
権限があれば一括ダウンロードができます

ソースコード

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();

		int[] d = new int[N+10];
		for(int i=2;i<=N;i++){
			for(int j=i*2;j<=N;j+=i){
				d[j]++;
			}
		}
		double e = 0;
		for(int i=2;i<=N;i++){
			if(d[i]==0) e+=1;
			else e+=Math.pow(1-p,d[i]);
		}
		System.out.println(e);
	}
}
0