## Codeforces Round #499 C. Fly （二分精度

``` 1 #include<iostream>
2 #include<cstdio>
3 #include <cctype>
4 #include<algorithm>
5 #include<cstring>
6 #include<cmath>
7 #include<string>
8 #include<cmath>
9 #include<set>
10 #include<vector>
11 #include<stack>
12 #include<queue>
13 #include<map>
14 using namespace std;
15 #define ll long long
16 #define mem(a,x) memset(a,x,sizeof(a))
17 #define se second
18 #define fi first
19 const int INF= 0x3f3f3f3f;
20 const int N=1e7+5;
21
22 int n,m,a[1005],b[1005];
23
24 bool check(double x)
25 {
26     double sum=m+x;
27
28     if(sum>m)
29         sum-= sum/a[1]; //起飞
30     else return 0;
31     for(int i=2;i<=n;i++)
32     {
33         if(sum>m)
34             sum-=sum/a[i];
35         else return 0;
36         if(sum>m)
37             sum-=sum/b[i];
38         else return 0;
39     }
40     if(sum>m)
41         sum-=sum/b[1];
42     else return 0;
43
44     if(sum>=m) return 1;
45     else return 0;
46 }
47
48 int main()
49 {
50     cin>>n>>m;
51     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
52     for(int i=1;i<=n;i++) scanf("%d",&b[i]);
53
54     double l=0,r=1e9,mid,ans=-1;
55     int flag=0;
56     while(r-l>=1e-6)
57     {
58         mid=(l+r)/2.0;
59         if(check(mid))
60         {
61             ans=mid;
62             r=mid;
63             flag=1;
64         }
65         else l=mid;
66     }
67     if(!flag)cout<<-1;
68     else printf("%.10f",ans);
69 }```