結果

問題 No.144 エラトステネスのざる
ユーザー 37zigen37zigen
提出日時 2016-03-22 02:04:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 74,016 KB
実行使用メモリ 62,528 KB
最終ジャッジ日時 2024-04-08 21:40:27
合計ジャッジ時間 7,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
58,224 KB
testcase_01 AC 158 ms
57,960 KB
testcase_02 AC 154 ms
58,228 KB
testcase_03 AC 153 ms
57,956 KB
testcase_04 AC 153 ms
57,984 KB
testcase_05 AC 138 ms
55,612 KB
testcase_06 AC 158 ms
58,208 KB
testcase_07 AC 158 ms
57,960 KB
testcase_08 AC 155 ms
57,960 KB
testcase_09 AC 161 ms
58,352 KB
testcase_10 AC 156 ms
58,296 KB
testcase_11 AC 158 ms
58,100 KB
testcase_12 AC 161 ms
57,944 KB
testcase_13 AC 218 ms
62,324 KB
testcase_14 AC 223 ms
62,384 KB
testcase_15 AC 218 ms
62,364 KB
testcase_16 AC 219 ms
62,472 KB
testcase_17 AC 217 ms
62,348 KB
testcase_18 AC 221 ms
62,528 KB
testcase_19 AC 208 ms
62,088 KB
権限があれば一括ダウンロードができます

ソースコード

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*i;j<=n;j+=i){
				a[j]++;
			}
		}
		return a;
	}
}
0