結果

問題 No.144 エラトステネスのざる
ユーザー 37zigen
提出日時 2016-03-22 02:04:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 74,780 KB
実行使用メモリ 56,756 KB
最終ジャッジ日時 2024-10-01 12:38:39
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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