期望,$dp$。
设$ans[n]$为答案,那么$ans[n]=(ans[a]+ans[b]+ans[c]+.....+ans[n])/cnt+1$,其中$a$,$b$,$c$......$n$均为$n$的因子。
化简得到$ans[n]=(ans[a]+ans[b]+ans[c]+......+cnt)/(cnt-1)$。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-6; void File() { freopen("D:\in.txt","r",stdin); freopen("D:\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0; while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } int T,n; double ans[100010]; vector<int>v[100010]; int main() { for(int i=1;i<=100000;i++) { for(int j=1;;j++) { if(i*j>100000) break; v[i*j].push_back(i); } } for(int i=2;i<=100000;i++) { for(int j=0;j<v[i].size();j++) ans[i]=ans[i]+ans[i/v[i][j]]; ans[i]=ans[i]+v[i].size(); ans[i]=ans[i]/(v[i].size()-1); } scanf("%d",&T); int cas=1; while(T--) { scanf("%d",&n); printf("Case %d: %lf ",cas++,ans[n]); } return 0; }