結果

問題 No.144 エラトステネスのざる
ユーザー HachimoriHachimori
提出日時 2015-02-05 23:42:13
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 601 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 51,584 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-05 13:03:13
合計ジャッジ時間 17,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
using namespace std;
const int BUF = 1000005;

int N;
double p;

void read() {
    cin >> N >> p;
}


void work() {
    double sum = 0;

    for (int i = 2; i <= N; ++i) {
        double toAdd = 1;
        for (int j = 2; j * j <= i; ++j) {
            if (j * j == i) {
                toAdd *= (1 - p);
            }
            else if (i % j == 0) {
                toAdd *= (1 - p);
                toAdd *= (1 - p);
            }
        }
        sum += toAdd;
    }
    
    printf("%.10lf\n", sum);
}


int main() {
    read();
    work();
    return 0;
}
0