結果

問題 No.144 エラトステネスのざる
ユーザー zaki_johozaki_joho
提出日時 2018-12-23 23:19:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 161,596 KB
実行使用メモリ 18,900 KB
最終ジャッジ日時 2023-10-26 02:40:35
合計ジャッジ時間 19,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
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 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    ld p;
    cin >> N >> p;
    vector<ld> dp(N + 1, 1);
    ld res = 0;
    for (int i = 2; i <= N; i++)
    {
        for (int j = 2; j * j <= i; j++)
        {
            if (i % j == 0)
            {
                dp[i] *= (1.0 - p) * (1.0 - p);
            }
        }
        res += dp[i];
    }
    cout << fixed << setprecision(10) << res << endl;
}
0