結果
| 問題 | 
                            No.2829 GCD Divination
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-12-11 22:05:40 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 732 bytes | 
| コンパイル時間 | 3,205 ms | 
| コンパイル使用メモリ | 245,752 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-11 22:05:45 | 
| 合計ジャッジ時間 | 4,325 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
 
using namespace std;
vector<int> factorize(int n) {
    vector<int> res;
    for (int i = 2; i*i <= n; ++i) {
        if (n%i != 0) continue;
        res.push_back(i);
        while (n%i == 0) n /= i;
    }
    if (n != 1) res.push_back(n);
    return res;
}
int main() {
    int n;
    cin >> n;
    
    auto fs = factorize(n);
    int m = fs.size();
    int m2 = 1<<m;
    
    double ans = 0;
    for (int s = 1; s < m2; ++s) {
        int d = 1;
        rep(i, m) if (s>>i&1) d *= fs[i];
        double now = d*1./(d-1);
        if (__builtin_parity(s)) ans += now;
        else ans -= now;
    }
    
    printf("%.10f\n", ans);
    
    return 0;
}