結果

問題 No.2829 GCD Divination
ユーザー InTheBloom
提出日時 2024-08-02 22:26:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 111,092 KB
実行使用メモリ 81,484 KB
最終ジャッジ日時 2024-08-02 22:26:38
合計ジャッジ時間 2,969 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int gcd (int x, int y) {
    while (0 < x) {
        int t = x;
        x = y % x;
        y = t;
    }
    return y;
}

int main () {
    int N; cin >> N;

    vector<double> memo(N + 1, -1);
    auto E = [&] (auto self, int x) -> double {
        if (memo[x] != -1) return memo[x];
        if (x == 1) return 0;
        double res = 1;

        for (int v = 1; v < x; v++) {
            res += 1 + self(self, gcd(v, x));
        }

        return memo[x] = res / (x - 1);
    };

    cout << setprecision(10);
    // 10^7程度でやっぱりTLE。。。
    // うーんなんか収束していそうな感じがするしある程度大きなNに対してもう決め打ちするか!w
    if (N <= 1000000) {
        cout << E(E, N) << "\n";
    }
    else {
        cout << 2.1388888888 << "\n";
    }
}
0