結果

問題 No.144 エラトステネスのざる
ユーザー misora192
提出日時 2020-05-27 22:34:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 916 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 171,024 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-13 03:53:09
合計ジャッジ時間 5,084 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	double p;
	cin >> n >> p;

	vector<bool> isprime(n+1, true);
	isprime[0] = isprime[1] = false;
	vector<int> primes;
	for(int i = 2; i <= n; i++){
		if(isprime[i]) primes.push_back(i);
		for(int j = 2 * i; j <= n; j += i) isprime[j] = false;
	}

	double ans = 0.0;
	for(int i = 2; i <= n; i++){
		ll cnt = 1;
		int y = i;
		for(int x : primes){
			ll t = 1;
			while(y % x == 0){
				y /= x;
				t++;
			}
			cnt *= t;
		}

		cnt -= 2;
		ans += pow(1.0 - p, cnt);
	}

	cout << fixed << setprecision(10);
	cout << ans << endl;
}
0