Advertisement
Farjana_akter

Untitled

Jul 16th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. #define mxn 100005
  6.  
  7. vector<ll>ting[mxn];
  8. double dp[mxn+5];
  9. bool vis[mxn+5];
  10.  
  11. void fun()
  12. {
  13. ll i,j,n,a,b,c;
  14. for(i=1; i<mxn; i++)
  15. {
  16. n=i;
  17. c=0;
  18. for(j=1; j<=sqrt(n); j++)
  19. {
  20. if(n%j==0)
  21. {
  22. ting[i].push_back(j);
  23. if(n/j!=j)
  24. ting[i].push_back(n/j);
  25. }
  26. }
  27. }
  28. }
  29.  
  30.  
  31. double dpfun(ll n)
  32. {
  33. if(n==1)
  34. return 0;
  35. if(vis[n])
  36. return dp[n];
  37. double sz=ting[n].size();
  38. if(sz==1)
  39. return 1;
  40. dp[n]=(sz/(sz-1.0));
  41. for(auto i: ting[n] )
  42. {
  43. if(i==n)
  44. continue;
  45. dp[n] += (double)(dpfun(i))/(sz-1.0);
  46. }
  47. vis[n]=1;
  48. return dp[n];
  49. }
  50.  
  51. int main()
  52. {
  53. fun();
  54. ll i,j,k,cas,n;
  55. int t;
  56. cin>>t;
  57. for(cas=1;cas<=t;cas++)
  58. {
  59. cin>>n;
  60. double ans=dpfun(n);
  61. printf("Case %d: %.8lf\n",cas,ans);
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement