結果

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

ソースコード

diff #

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