結果

問題 No.144 エラトステネスのざる
ユーザー koyumeishi
提出日時 2015-02-06 00:11:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-06-23 09:02:02
合計ジャッジ時間 1,755 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int main(){
	int N;
	cin >> N;

	double p;
	cin >> p;

	vector<double> v(N+1, 1.0);
	v[0] = v[1] = 0.0;

	vector<int> cnt(N+1, 0);

	for(int i=2; i<=N/2; i++){
		for(int j=2*i; j<=N; j+=i){
			cnt[j]++;
		}
	}

	double ans = 0;
	for(int i=2; i<=N; i++){
		ans += pow(1.0-p, cnt[i]);
	}

	printf("%.6f\n", ans);
	return 0;
}
0