-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLOJ-1038.cpp
39 lines (38 loc) · 853 Bytes
/
LOJ-1038.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
#include<bits/stdc++.h>
using namespace std;
double dp[100002];
double rec(int ii) {
if(ii==1)return 0;
if(dp[ii]>(-1.0))return dp[ii];
int lim=sqrt(ii)+1,cnt=2;
double ret=2.0;
for(int i=2;i<lim;i++){
if(ii%i==0){
if(i!=(ii/i)){
ret+=(1+rec(ii/i));
ret+=(1+rec(i));
cnt+=2;
}else{
ret+=(1+rec(ii/i));
cnt++;
}
}
}
ret/=(cnt-1);
return dp[ii]=ret;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
int t;
scanf("%d",&t);
memset(dp,-1,sizeof(dp));
for(int z=1; z<=t; z++) {
int n;
scanf("%d",&n);
printf("Case %d: %.9lf\n",z,rec(n));
//cout<<"Case "<<z<<": "<<rec(n)<<"\n";
}
return 0;
}