結果
問題 | No.2829 GCD Divination |
ユーザー | kotatsugame |
提出日時 | 2024-08-02 21:39:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,811 ms / 2,000 ms |
コード長 | 839 bytes |
コンパイル時間 | 902 ms |
コンパイル使用メモリ | 88,800 KB |
実行使用メモリ | 81,476 KB |
最終ジャッジ日時 | 2024-08-02 21:40:09 |
合計ジャッジ時間 | 13,984 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function 'long double solve(int)': main.cpp:35:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 35 | for(auto[v,c]:nxt)ans+=solve(gcd(v,N))*c; | ^
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<map> #include<cassert> #include<iomanip> using namespace std; int gcd(int a,int b) { while(b) { int t=a%b; a=b; b=t; } return a; } int to[10000001]; long double memo[10000001]; long double solve(int N) { if(N==1)return 0; if(memo[N])return memo[N]; vector<pair<int,int> >nxt; { vector<int>tov(to+1,to+N); sort(tov.begin(),tov.end()); for(int v:tov) { if(!nxt.empty()&&nxt.back().first==v)nxt.back().second++; else nxt.push_back(make_pair(v,1)); } } long double ans=0; for(auto[v,c]:nxt)ans+=solve(gcd(v,N))*c; ans+=N; ans/=N-1; return memo[N]=ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N;cin>>N; for(int g=1;g<N;g++)if(N%g==0)for(int i=g;i<N;i+=g)to[i]=g; cout<<fixed<<setprecision(16)<<solve(N)<<endl; }