結果

問題 No.144 エラトステネスのざる
ユーザー rsk0315
提出日時 2019-03-17 19:10:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 387 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 47,360 KB
最終ジャッジ日時 2025-01-06 22:34:20
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |   scanf("%d %lf", &N, &p);
      |   ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>

int main() {
  int N;
  double p;
  scanf("%d %lf", &N, &p);

  std::vector<double> zaru(N+1, 1.0);
  double res = 0;
  for (int i = 2; i <= N; ++i) {
    res += zaru[i];
    for (int j = i+i; j <= N; j += i)
      zaru[j] *= 1-p;
  }

  // for (int i = 2; i <= N; ++i)
  //   fprintf(stderr, "%2d: %.6f\n", i, zaru[i]);

  printf("%.12f\n", res);
}
0