結果
| 問題 |
No.2829 GCD Divination
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-02 23:15:08 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,721 ms / 2,000 ms |
| コード長 | 665 bytes |
| コンパイル時間 | 6,527 ms |
| コンパイル使用メモリ | 254,936 KB |
| 最終ジャッジ日時 | 2025-02-23 20:28:39 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(l);i<(int)(r);i++)
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector phi(N+1,0.0);
for(int i=0;i<=N;i++)phi[i]=i;
for(int i=2;i<=N;i++){
if(phi[i]!=i)continue;
for(int j=i;j<=N;j+=i){
phi[j]=phi[j]/i*(i-1);
}
}
vector dp(N+1,0.0);
for(int i=1;i<=N;i++){
if(i>1)dp[i]=(1+dp[i]*i)/(double)(i-1);
for(int j=2;j*i<=N;j++){
dp[j*i]+=phi[j]*(dp[i]+1)/((double)j*i);
}
}
cout<<setprecision(10)<<dp[N]<<'\n';
}