Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- #define mxn 100005
- vector<ll>ting[mxn];
- double dp[mxn+5];
- bool vis[mxn+5];
- void fun()
- {
- ll i,j,n,a,b,c;
- for(i=1; i<mxn; i++)
- {
- n=i;
- c=0;
- for(j=1; j<=sqrt(n); j++)
- {
- if(n%j==0)
- {
- ting[i].push_back(j);
- if(n/j!=j)
- ting[i].push_back(n/j);
- }
- }
- }
- }
- double dpfun(ll n)
- {
- if(n==1)
- return 0;
- if(vis[n])
- return dp[n];
- double sz=ting[n].size();
- if(sz==1)
- return 1;
- dp[n]=(sz/(sz-1.0));
- for(auto i: ting[n] )
- {
- if(i==n)
- continue;
- dp[n] += (double)(dpfun(i))/(sz-1.0);
- }
- vis[n]=1;
- return dp[n];
- }
- int main()
- {
- fun();
- ll i,j,k,cas,n;
- int t;
- cin>>t;
- for(cas=1;cas<=t;cas++)
- {
- cin>>n;
- double ans=dpfun(n);
- printf("Case %d: %.8lf\n",cas,ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement