結果
問題 | No.144 エラトステネスのざる |
ユーザー |
|
提出日時 | 2023-06-15 00:24:25 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 191 ms / 2,000 ms |
コード長 | 1,127 bytes |
コンパイル時間 | 3,295 ms |
コンパイル使用メモリ | 251,984 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-06-23 05:08:06 |
合計ジャッジ時間 | 5,284 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "debug.hpp"#else#define debug(...) 1#endifvector<int> sieve(int n) {vector<int> min_factor(n + 1);for (int i = 1; i <= n; i++) {min_factor[i] = i;}for (int i = 2; i * i <= n; i++) {if (min_factor[i] == i) {for (int j = i + i; j <= n; j += i) {if (min_factor[j] > i) {min_factor[j] = i;}}}}return min_factor;}map<int, int> factor(vector<int> &min_factor, int m) {map<int, int> ret;while (m > 1) {ret[min_factor[m]]++;m /= min_factor[m];}return ret;}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;auto v = sieve(n);double p;cin >> p;double ans = 0;for (int i = 2; i <= n; i++) {auto mp = factor(v, i);int cnt = 1;for (auto [x, y] : mp) {cnt *= (y + 1);}ans += pow(1 - p, cnt - 2);}cout << fixed << setprecision(15) << ans << '\n';}