結果

問題 No.144 エラトステネスのざる
ユーザー AnchorBluesAnchorBlues
提出日時 2023-03-07 22:51:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,184 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 174,460 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-18 05:37:41
合計ジャッジ時間 5,325 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll ceilll(ll x, ll y) { return (x + y - 1) / y; }
ll mod(ll x, ll y) { return (x + 10000000) % y; }

// 約数全列挙
vector<ll> all_divisors(ll K) {
    vector<ll> ret;
    for (ll i = 1; i * i <= K; i++) {
        if (K % i != 0) continue;
        ret.push_back(i);
        if (i * i != K) ret.push_back(K / i);
    }
    return ret;
}

// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

double memo[10000000];

double powdouble(double a, ll x) {
    if (x == 0) return 1;
    if (memo[x]) return memo[x];
    memo[x] = powdouble(a, x - 1) * a;
    return memo[x];
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll N;
    cin >> N;
    double p;
    cin >> p;
    double ret = 0;
    for (int i = 2; i <= N; i++) {
        auto tmp = all_divisors(i);
        // print_vector(tmp);
        ret += powdouble(1 - p, tmp.size() - 2);
    }
    std::cout << fixed << setprecision(12) << ret << "\n";
    return 0;
}
0