結果

問題 No.144 エラトステネスのざる
コンテスト
ユーザー addx
提出日時 2026-03-30 19:49:11
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,441 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,343 ms
コンパイル使用メモリ 375,640 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2026-03-30 19:49:28
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = unsigned __int128_t;
using mint = atcoder::static_modint<998244353>;
const int mod = 998244353;
#include <chrono>
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
template<class T>
bool chmin(T& a, const T& b){
    if (b < a){
        a = b;
        return true;
    }
    else { 
        return false;
    }
}
template<class T> 
bool chmax(T& a, const T& b){
    if (a < b){
        a = b;
        return true;
    }
    else {
        return false;
    }
}

void solve(){
    int n;
    double p;
    cin >> n >> p;
    p = 1.0 - p;
    vector<int> sum(n + 1);
    vector<int> cnt(n + 1);
    for (int i = 2; i <= n; i++){
        for (int j = i; j <= n; j += i){
            cnt[j]++;
        }
        sum[cnt[i] - 1]++;
    }
    vector<double> d(n + 1);
    d[0] = 1;
    for (int i = 1; i <= n; i++){
        d[i] = d[i - 1] * p;
    }
    double ans = 0;
    for (int i = 0; i <= n; i++){
        ans += sum[i] * d[i];
    }
    cout << ans << '\n';
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;   
    while(t--){
        cout << fixed << setprecision(15);          
        solve();
    }   
}
0