結果

問題 No.144 エラトステネスのざる
ユーザー penguinshunyapenguinshunya
提出日時 2019-04-01 16:29:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 198,336 KB
実行使用メモリ 11,868 KB
最終ジャッジ日時 2023-08-16 17:37:55
合計ジャッジ時間 4,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 74 ms
11,704 KB
testcase_14 AC 89 ms
11,832 KB
testcase_15 AC 96 ms
11,832 KB
testcase_16 AC 91 ms
11,868 KB
testcase_17 AC 93 ms
11,724 KB
testcase_18 AC 93 ms
11,848 KB
testcase_19 AC 69 ms
11,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

f64 dp[1000010];

void solve(int n, f64 p) {
  repi(i, 2, n + 1) {
    f64 c = pow(1 - p, dp[i]);
    dp[i] = dp[i - 1] * (1 - c) + (dp[i - 1] + 1) * c;
    for (int j = i * 2; j <= n; j += i) dp[j]++;
  }
  cout << dp[n] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  f64 p;
  cin >> n >> p;
  solve(n, p);
  return 0;
}
0