結果

問題 No.2829 GCD Divination
ユーザー ja14378
提出日時 2024-08-02 22:46:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 673 bytes
コンパイル時間 4,180 ms
コンパイル使用メモリ 256,404 KB
最終ジャッジ日時 2025-02-23 20:14:43
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using ll = long long;
#define MOD 1000000007
#define Mod 998244353
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;
using namespace atcoder;

map<int, double> dp;
double rec(int n) {
    if (dp.count(n)) return dp[n];
    if (n == 1) return 0;
    double s = 0;
    for (int m = 2; m*m <= n; m++) {
        if (n % m == 0) {
            s += rec(m);
            if (n/m != m) s += rec(m);
        }
    }
    return dp[n] = (n + s)/(n - 1);
}

int main() {
    ios::sync_with_stdio(0);cin.tie();
    int N;
    cin >> N;
    cout << fixed << setprecision(12) << rec(N) << endl;
}
0