結果

問題 No.144 エラトステネスのざる
ユーザー Im_GimletIm_Gimlet
提出日時 2020-07-15 14:58:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 163,396 KB
実行使用メモリ 7,644 KB
最終ジャッジ日時 2023-08-14 03:38:23
合計ジャッジ時間 4,818 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,544 KB
testcase_01 AC 5 ms
7,512 KB
testcase_02 AC 5 ms
7,544 KB
testcase_03 AC 5 ms
7,492 KB
testcase_04 AC 4 ms
7,644 KB
testcase_05 AC 4 ms
7,576 KB
testcase_06 AC 5 ms
7,544 KB
testcase_07 AC 4 ms
7,568 KB
testcase_08 AC 5 ms
7,544 KB
testcase_09 AC 5 ms
7,536 KB
testcase_10 AC 5 ms
7,520 KB
testcase_11 AC 5 ms
7,580 KB
testcase_12 AC 5 ms
7,492 KB
testcase_13 AC 328 ms
7,504 KB
testcase_14 AC 333 ms
7,584 KB
testcase_15 AC 315 ms
7,520 KB
testcase_16 AC 311 ms
7,544 KB
testcase_17 AC 311 ms
7,524 KB
testcase_18 AC 329 ms
7,500 KB
testcase_19 AC 55 ms
7,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
int d[1000100];

int main() {
    cin >> n;
    long double p; cin >> p;
    long double ans = 0.0;
    memset(d, 0, sizeof(d));
    for(int i = 2; i <= n; ++i) {
        for(int m = i; m <= n; m+=i) {
            d[m]++;
        }
        ans += powl((1LL-p), d[i]-1);
    }
    cout << setprecision(14) << ans << endl;
}
0