結果

問題 No.2829 GCD Divination
ユーザー GOTKAKOGOTKAKO
提出日時 2024-08-02 22:12:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 915 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 208,836 KB
実行使用メモリ 681,356 KB
最終ジャッジ日時 2024-08-02 22:12:54
合計ジャッジ時間 5,623 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<vector<int>> Ds(N+1);
    for(int i=1; i<=N; i++) for(int k=i; k<=N; k+=i) Ds.at(k).push_back(i);
    vector<double> P(N+1);
    double answer = 0;
    P.at(N) = 1;
    for(int i=N; i>1; i--) if(P.at(i) > 1e-10){
        int n = Ds.at(i).size();
        vector<int> C(n);
        for(int k=n-1; k>=0; k--){
            int d = Ds.at(i).at(k);
            int now = N/d;
            for(int l=k+1; l<n; l++) if(Ds.at(i).at(l)%d == 0) now -= C.at(l);
            C.at(k) = now;
        }
        double multi = N/(0.0+N-C.at(n-1));
        answer += multi*P.at(i);
        for(int k=0; k<n-1; k++){
            int d = Ds.at(i).at(k);
            P.at(d) += P.at(i)*C.at(k)/(N-C.at(n-1));
        }
    }
    cout << fixed << setprecision(20) << answer << endl;

}
0