結果

問題 No.144 エラトステネスのざる
ユーザー 37zigen
提出日時 2016-03-22 01:50:35
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 684 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 77,812 KB
実行使用メモリ 65,692 KB
最終ジャッジ日時 2024-10-01 12:37:17
合計ジャッジ時間 8,079 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

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