結果
問題 | No.2829 GCD Divination |
ユーザー |
|
提出日時 | 2024-08-02 22:18:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 2,204 ms |
コンパイル使用メモリ | 208,400 KB |
最終ジャッジ日時 | 2025-02-23 20:06:43 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; map<int,double,greater<>> P; double answer = 0; P[N] = 1; for(auto [i,p] : P){ if(i == 1) break; vector<int> D; for(int k=1; k*k<=i; k++){ if(i%k) continue; D.push_back(k); if(k*k != i) D.push_back(i/k); } sort(D.begin(),D.end()); int n = D.size(); vector<int> C(n); for(int k=n-1; k>=0; k--){ int d = D.at(k); int now = N/d; for(int l=k+1; l<n; l++) if(D.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; for(int k=0; k<n-1; k++){ int d = D.at(k); P[d] += p*C.at(k)/(N-C.at(n-1)); } } cout << fixed << setprecision(20) << answer << endl; }