結果

問題 No.144 エラトステネスのざる
ユーザー 37zigen37zigen
提出日時 2016-03-22 01:50:35
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 684 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 74,132 KB
実行使用メモリ 69,672 KB
最終ジャッジ日時 2024-04-08 21:39:12
合計ジャッジ時間 8,162 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
64,912 KB
testcase_01 AC 152 ms
57,972 KB
testcase_02 AC 149 ms
58,100 KB
testcase_03 AC 150 ms
57,952 KB
testcase_04 AC 152 ms
58,224 KB
testcase_05 AC 151 ms
57,948 KB
testcase_06 AC 157 ms
58,236 KB
testcase_07 AC 157 ms
58,232 KB
testcase_08 AC 155 ms
56,304 KB
testcase_09 AC 153 ms
58,120 KB
testcase_10 AC 155 ms
58,224 KB
testcase_11 AC 156 ms
58,216 KB
testcase_12 AC 154 ms
57,976 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder242;
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[] a=theNumberOfDivisors(n);//a[n]=nの約数の個数
//		for(int i=0;i<=n;i++){
//			System.out.println("a["+i+"]="+a[i]);
//		}
		double expectedValue=0;
		for(int i=2;i<=n;i++){
			expectedValue+=Math.pow(1-p, a[i]);
		}
		System.out.println(expectedValue);
	}
	public static int[] theNumberOfDivisors(int n){//1と自分自身を除く約数の個数
		int[] a=new int[n+1];
		for(int i=2;i<=n;i++){
			for(int j=2;j<i;j++){
				if(i%j==0)a[i]++;
			}
		}
		return a;
	}
}
0