結果

問題 No.2829 GCD Divination
ユーザー makichanmakichan
提出日時 2024-08-02 21:43:22
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 5,395 ms
コンパイル使用メモリ 323,036 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-02 21:43:29
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::static_modint<998244353>;
//using mint = atcoder::static_modint<1000000007>;
using namespace std;
using namespace atcoder;
using ld = long double;
using ll = long long;
#define mp(a,b) make_pair(a,b)
#define rep(i,s,n) for(int i=s; i<n; i++)
const vector<int> dx{1,0,-1,0},dy{0,1,0,-1};

map<int,ld> memo;

ld dfs(int x){
    if(memo.count(x))return memo[x];
    if(x==1)return 0;
    set<int> S;
    for(int i=1; i*i<=x; i++)if(x%i==0)S.insert(-i),S.insert(-x/i);
    map<int,int> f;
    S.erase(-x);
    f[x]=1;
    ld output=0;
    for(auto y:S){

        y=-y;
        int cnt=x/y;
        for(auto [a,b]:f)if(a%y==0)cnt-=b;
        output+=cnt*dfs(y);
        f[y]=cnt;
    }
    // if(x==4){
    //     for(auto [x,y]:f)cout << x << " " << y << "\n";
    // }
    output+=x;
    output/=x-1;
    memo[x]=output;
    return output;
}
int main(){
    int n;
    cin >> n;
    cout << setprecision(16);
    cout << dfs(n);
}
0