結果

問題 No.144 エラトステネスのざる
ユーザー PachicobuePachicobue
提出日時 2018-12-19 21:05:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 80,952 KB
実行使用メモリ 23,064 KB
最終ジャッジ日時 2023-10-26 00:06:21
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
using ld = long double;
int main()
{
    int N;
    ld P;
    std::cin >> N >> P;
    std::vector<ld> p(N + 1, 1);
    for (int i = 1; i <= N; i++) { p[i] = (1 - P) * p[i - 1]; }
    std::vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; i++) {
        for (int j = 2; i * j <= N; j++) { cnt[i * j]++; }
    }
    ld ans = 0;
    for (int i = 2; i <= N; i++) { ans += p[cnt[i]]; }
    std::cout << std::fixed << std::setprecision(15) << ans << std::endl;
    return 0;
}
0