結果

問題 No.144 エラトステネスのざる
ユーザー latte0119
提出日時 2015-10-26 18:25:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 159,344 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-09-13 11:39:08
合計ジャッジ時間 2,433 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     scanf("%d%lf",&N,&p);
      |     ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()

int N;
double p;

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

    fill_n(f,1010101,1);
    f[0]=f[1]=0;

    double a=0;

    for(int i=2;i<=N;i++){
        a+=f[i];
        for(int j=2;i*j<=N;j++)f[i*j]*=(1-p);
    }

    printf("%.20lf\n",a);
    return 0;
}
0