https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/C

【题意】

给定一个数D,每次随机选取这个数的一个因子x得到新的数D=D/x,知道D变成1,问操作步数的期望

【思路】

dp[50]=(dp[1]+dp[2]+dp[5]+dp[10]+dp[25]+dp[50]+6)/6,则dp[50]=(dp[1]+dp[2]+dp[5]+dp[10]+dp[25]+6)/5

【Accepted】

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<string>
 6 #include<cstring>
 7 
 8 using namespace std;
 9 typedef long long ll;
10 typedef double db;
11 int n;
12 const int maxn=1e5+3;
13 const int mod=1e8;
14 db dp[maxn];
15 int cnt[maxn];
16 void Init()
17 {
18     memset(cnt,0,sizeof(cnt));
19     dp[1]=0.0;
20     for(int i=1;i<maxn;i++)
21     {
22         if(i!=1)
23         {
24             dp[i]=(dp[i]+1.0)/cnt[i];    
25         }    
26         for(int k=2*i;k<maxn;k+=i)
27         {
28             cnt[k]++;
29             dp[k]+=dp[i]+1.0;
30         }
31     }    
32 }
33 int main()
34 {
35     Init();
36     int T;
37     scanf("%d",&T);
38     int kas=0;
39     while(T--)
40     {
41         scanf("%d",&n);
42         printf("Case %d: %.10f\n",++kas,dp[n]);    
43     }
44     return 0;
45 }
View Code

相关文章:

  • 2021-08-14
  • 2021-09-21
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-10-12
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
相关资源
相似解决方案