-
Notifications
You must be signed in to change notification settings - Fork 1
/
1038 - Race to 1 Again.cpp
51 lines (51 loc) · 1.09 KB
/
1038 - Race to 1 Again.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
double dp[100001];
vector<int> divisor[100001];
double fun(int num)
{
if(num==1) return 0;
if(dp[num]!=-1) return dp[num];
double ret = 0;
for(int i=0; i<divisor[num].size(); i++){
ret+=(1+fun(divisor[num][i]));
}
double d = divisor[num].size()+2;
d = 1.0/(d-1);
ret = 2.0*d + d*ret;
return dp[num] = ret;
}
void getDivisor(unsigned int num)
{
int sq = sqrt(num);
for(unsigned int i=2; i<=sq; i++){
if(num%i==0){
int a = num/i;
if(a!=i) divisor[num].push_back(i);
divisor[num].push_back(a);
}
}
}
void process()
{
int cnt=0;
for(int i=1; i<=100000; i++){
dp[i] = -1;
getDivisor(i);
}
for(int i=1; i<=100000; i++){
dp[i] = fun(i);
}
}
int main()
{
ios_base::sync_with_stdio(0);
process();
int tc,n;
cin>>tc;
for(int cs=1; cs<=tc; cs++){
cin>>n;
cout<<"Case "<<cs<<": "<<fixed<<setprecision(10)<<dp[n]<<endl;
}
return 0;
}