結果

問題 No.144 エラトステネスのざる
ユーザー nanophoto12nanophoto12
提出日時 2021-01-24 15:21:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 2,770 bytes
コンパイル時間 6,544 ms
コンパイル使用メモリ 262,452 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-08-30 22:42:32
合計ジャッジ時間 5,991 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 47 ms
7,280 KB
testcase_14 AC 46 ms
7,016 KB
testcase_15 AC 47 ms
7,232 KB
testcase_16 AC 46 ms
7,304 KB
testcase_17 AC 47 ms
7,188 KB
testcase_18 AC 50 ms
7,248 KB
testcase_19 AC 46 ms
7,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void chmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void chmin(T& reference, T value) {
	reference = min(reference, value);
}

class Primes {
private:
	vector<int> Prime_Number;
	vector<bool> is_prime_;
public:
	Primes(int N) {
		is_prime_.resize(N + 1, true);
		is_prime_[0] = is_prime_[1] = false;
		for (int i = 0; i < N + 1; i++) {
			if (is_prime_[i]) {
				Prime_Number.push_back(i);
				for (int j = 2 * i; j <= N; j += i) is_prime_[j] = false;
			}
		}
	}
	int operator[](int i) { return Prime_Number[i]; }
	int size() { return Prime_Number.size(); }
	int back() { return Prime_Number.back(); }
	bool isPrime(int q) { return is_prime_[q]; }
};

class Divisor {
private:
	vector<ll> F;
	vector<pair<ll, ll>> pfactorize;
public:
	Divisor(ll N) {
		for (ll i = 1; i * i <= N; i++) {
			if (N % i == 0) {
				F.push_back(i);
				if (i * i != N) F.push_back(N / i);
			}
		}
		sort(begin(F), end(F));
		Primes p((ll)sqrt(N) + 1);
		for (int i = 0; i < p.size(); i++) {
			pfactorize.emplace_back(p[i], 0);
			while (N % p[i] == 0) {
				N /= p[i];
				pfactorize.back().second++;
			}
			if (pfactorize.back().second == 0) pfactorize.pop_back();
		}
		if (N > 1) pfactorize.emplace_back(N, 1);
	}
	int size() { return F.size(); }
	const vector<pair<ll, ll>>& pfac() { return pfactorize; }
	ll operator[](int k) { return F[k]; }
	const vector<ll>& factors() { return F; }
};
#include <atcoder/all>
using namespace atcoder;

typedef modint1000000007 mint;

struct BIT {
	typedef double input_t;

	vector<input_t> bit_;
	const long long n_;

	BIT(long long n) :n_(n) {
		bit_.resize(n + 1LL, 0);
	}

	input_t sum(int i) {
		input_t s = 0;
		while (i > 0) {
			s += bit_[i];
			i -= i & (-i);
		}
		return s;
	}

	void add(int i, input_t x) {
		while (i <= n_) {
			bit_[i] += x;
			i += (i & (-i));
		}
	}
};

constexpr double mpow(double x, ll n) {
	double ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x;
		x = x * x;
		n = n >> 1;
	}
	return ans;
}

int main() {
	ll n;
	double p;
	cin >> n >> p;
	vector<int> table(n + 1, 0);
	for (int i = 2; i <= n; i++) {
		for (int j = 1; i * j <= n; j++) {
			table[i * j]++;
		}
	}
	double ex = 0;
	for (int i = 2; i <= n; i++) {
		int c = table[i];
		double q = mpow(1-p, c - 1);
		ex += q;
	}
	cout << setprecision(10) << fixed << ex << endl;
	return 0;
}

0