結果

問題 No.144 エラトステネスのざる
ユーザー misora192misora192
提出日時 2020-05-27 22:34:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 916 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 167,808 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 05:23:18
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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