結果

問題 No.144 エラトステネスのざる
ユーザー chocorusk
提出日時 2018-10-13 03:43:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 3,169 ms
コンパイル使用メモリ 89,780 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-10-12 17:56:13
合計ジャッジ時間 2,767 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	double p0;
	cin>>n>>p0;
    double p[1000001];
	fill(p+2, p+n+1, 1.0);
	for(int i=2; i<=n; i++){
		for(int j=2*i; j<=n; j+=i){
			p[j]*=(1.0-p0);
		}
	}
	double ans=0;
	for(int i=2; i<=n; i++) ans+=p[i];
	printf("%.7lf\n", ans);
    return 0;
}
0