結果
| 問題 |
No.2829 GCD Divination
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-25 16:24:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,582 bytes |
| コンパイル時間 | 1,603 ms |
| コンパイル使用メモリ | 131,028 KB |
| 最終ジャッジ日時 | 2025-02-24 01:53:42 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 32 |
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const int MAXN=3*1000000;
vector<pair<ll,ll>> calc_gcd(ll n){
vector<ll> f;
for(ll v=1;v*v<=n;v++){
if(n%v==0){
f.push_back(v);
if(n/v!=v){
f.push_back(n/v);
}
}
}
sort(f.rbegin(),f.rend());
map<ll,ll> cnt;
vector<pair<ll,ll>> ans;
for(ll v:f){
cnt[v]=n/v;//1~nまでの数でvの倍数の個数
for(ll t=2*v;t<=n;t+=v){
//約数の倍数は除外
cnt[v]-=cnt[t];
}
ans.emplace_back(v,cnt[v]);
}
return ans;
}
int main(){
ll N;
cin>>N;
vector<ll> factor;
for(ll d=1;d*d<=N;d++){
if(N%d==0){
factor.push_back(d);
if(N/d!=d){
factor.push_back(N/d);
}
}
}
sort(factor.begin(),factor.end());
vector<double> dp(N+1,0);
for(ll v:factor){
if(v==1) continue;
auto array=calc_gcd(v);
double d=0;
for(auto [p,cnt]:array){
if(p==v) continue;
d+=(1.0*cnt/v)*dp[p];
}
d+=1;
d=(d*v)/(v-1);
dp[v]=d;
}
printf("%.10f\n",dp[N]);
}