結果

問題 No.144 エラトステネスのざる
ユーザー latte0119latte0119
提出日時 2015-10-26 18:25:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 143,020 KB
実行使用メモリ 11,632 KB
最終ジャッジ日時 2023-10-11 12:51:45
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,360 KB
testcase_01 AC 6 ms
11,432 KB
testcase_02 AC 6 ms
11,420 KB
testcase_03 AC 6 ms
11,576 KB
testcase_04 AC 5 ms
11,324 KB
testcase_05 AC 6 ms
11,436 KB
testcase_06 AC 5 ms
11,428 KB
testcase_07 AC 5 ms
11,320 KB
testcase_08 AC 6 ms
11,392 KB
testcase_09 AC 5 ms
11,492 KB
testcase_10 AC 5 ms
11,592 KB
testcase_11 AC 5 ms
11,516 KB
testcase_12 AC 5 ms
11,576 KB
testcase_13 AC 47 ms
11,420 KB
testcase_14 AC 47 ms
11,424 KB
testcase_15 AC 47 ms
11,620 KB
testcase_16 AC 47 ms
11,632 KB
testcase_17 AC 48 ms
11,440 KB
testcase_18 AC 50 ms
11,332 KB
testcase_19 AC 47 ms
11,616 KB
権限があれば一括ダウンロードができます

ソースコード

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