結果

問題 No.144 エラトステネスのざる
ユーザー koba-e964
提出日時 2015-06-11 22:44:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 386 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 159,668 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-07-06 15:46:50
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int N=1e6 + 10;
double a[N];
int main(){
  int n;
  double p;
  cin >> n >> p;
  a[0] = a[1] = 0;
  for(int i=2;i<N;i++) { 
    a[i]=1; 
  }
  for (int i = 2; i < N; i++) {
    for (int j = i * 2; j < N; j += i) {
      a[j] *= (1 - p);
    }
  }
  double s = 0;
  for (int i=2;i<=n;i++) {
    s += a[i];
  }
  printf("%.9f\n", s);
}
0