Problem:
Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define AA first
#define BB second
#define ONES(x) __builtin_popcount(x)
#define _ <<" "<<
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
const double eps=1e-6;
const int mod=1e9+7;
const double PI=acos(-1.0);
inline int read(){ int num;    scanf("%2d",&num);   return num;}
const int maxn=1e5+7;
//numerator分子  denominator分母
class Rational {
	public:
    Rational(int n=0,int d=1):num(n),den(d) {} //有参构造函数
    friend Rational operator+(const Rational &r1,const Rational &r2);//相加
    friend Rational operator-(const Rational &r1,const Rational &r2);//相减
    friend Rational operator/(const Rational &r1,const Rational &r2);//相除
    friend Rational operator*(const Rational &r1,const Rational &r2);//相乘
    void simplify();//对有理数进行化简
    void display();  //显示结果
    double num;
    double den;

};
Rational operator+(const Rational &r1,const Rational &r2) {
    Rational r;
    r.num = r1.den*r2.num+r1.num*r2.den;//相加的分子等于r1分母和r2分子相乘，r1分子和r2分母相乘之和
    r.den = r1.den*r2.den;//分母等于两个有理数分母的相乘
    r.simplify();//调用simplify对结果进行化简
    return r;//将结果返回
}
Rational operator-(const Rational &r1,const Rational &r2) {
    Rational r;
    r.num = r1.num*r2.den-r1.den*r2.num;//相加的分子等于r1分母和r2分子相乘，r1分子和r2分母相乘之差
    r.den = r1.den*r2.den;//分母等于两个有理数分母的相乘
    r.simplify();
    return r;
}
Rational operator/(const Rational &r1,const Rational &r2) {
    Rational r;
    if(r1.den==0||r2.den==0||r2.num==0) {
        cout<<"分母或者除数不能为0"<<endl;
    } else if(r1.num==0) {
        cout<<"0/0"<<endl;
    } else {
        r.num = r1.num*r2.den;//相除的分子等于r1分子和r2分母相乘
        r.den = r1.den*r2.num;//分母等于两个r1分母和r2分子相乘
        r.simplify();
        return r;
    }
}
Rational operator*(const Rational &r1,const Rational &r2) {
    Rational r;
    if(r1.den==0||r2.den==0) {
        cout<<"分母不能为0"<<endl;
    } else if(r1.num==0||r2.num==0) {
        cout<<"0/0"<<endl;
    } else {
        r.num = r1.num*r2.den;//分子等于r1分子和r2分母相乘
        r.den = r1.den*r2.num;//分母等于两个r1分母和r2分子相乘
        r.simplify();
        return r;
    }
}
void Rational::simplify() {
    int i,j,temp;
    i=abs(den);
    j=abs(num);
    //如果i对j取余不为0，辗转相除法求最大公约数
    while(temp=i%j) {
        i=j;
        j=temp;
    }
    den/=j;
    num/=j;
    if(den<0) {
        den=-den;
        num=-num;
    }
}
void Rational::display() {
    if(num==0||den==0) {

    } else {
        cout<<num<<"/"<<den<<endl;
    }
}
int main()
{
	Rational r;
    Rational r1(1,3),r2(0,5);
	int a,b,c,d;
	scanf("%d",&a);b=read();//getchar();//c=read();d=read();
	Rational ans(0,1);Rational tmp=(1,a);
	for(int i=1;i<=a;i++)
	{
		int t=i;int cnt=0;
		while(t<b)
		{
			t*=2;cnt++;
		}
		Rational tt(1,1);Rational ttt=(1,2);
		for(int j=1;j<=cnt;j++) 
		tt=tt*ttt;
		ans=ans+tt;
		long double aa=ans.num;long double bb=ans.den; 
	    //cout<<aa<<" "<<bb<<endl;
	}
	ans=ans*tmp;
	ans.simplify();
	long double aa=ans.num;long double bb=ans.den; 
	//cout<<aa<<" "<<bb<<endl;
	long double aaaa=aa/bb;
	printf("%.14Lf\n",aaaa);
	return 0;
}