結果

問題 No.144 エラトステネスのざる
ユーザー kumakumaaaaakumakumaaaaa
提出日時 2021-02-18 11:46:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 167,424 KB
実行使用メモリ 11,256 KB
最終ジャッジ日時 2023-10-12 20:20:45
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 340 ms
11,256 KB
testcase_14 AC 347 ms
10,972 KB
testcase_15 AC 328 ms
10,960 KB
testcase_16 AC 326 ms
10,856 KB
testcase_17 AC 323 ms
10,808 KB
testcase_18 AC 341 ms
11,232 KB
testcase_19 AC 70 ms
11,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  ld P;
  cin >> N >> P;
  vector<ll> num(N + 1, 0);
  for (ll i = 2; i <= N; ++i) {
    ll cnt = 2;
    while (cnt * i <= N) {
      num.at(cnt * i) += 1;
      cnt += 1;
    }
  }
  ld ans = 0;
  for (ll i = 2; i <= N; ++i) {
    ans += 1 * pow(1.0 - P, num.at(i));
  }
  cout << fixed << setprecision(15);
  cout << ans << "\n";
}
0