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



Sample input:
3 10


Sample output:
0.145833333333

Submission status: Runtime Error

Solution code:
from math import log
from math import ceil
n,k=map(int,input().split())
ans=0
for i in range(n):
  a=ceil(k/i)
  x=ceil(log(a,2))
  ans+=0.5**x
print(ans/n)

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())


ans=0
if N>=K:
    SA=N-K
    NN=N
    N=K-1
    point=K//2

    if point >N:
        point=N

    ans+=0.5*(N-point)
    n=point
    count=K//(2*n)+1
    ans+=(0.5)**count
    harf=(0.5)**count


    for i in range (n-1):
        harf=0.5*harf
        ans+=harf
    print(((SA+1)+ans)/NN)
    exit(0)
else:

    point=K//2

    if point >N:
        point=N

    ans+=0.5*(N-point)
    n=point
    count=K//(2*n)+1
    ans+=(0.5)**count
    harf=(0.5)**count

    for i in range (n-1):
        harf=0.5*harf
        ans+=harf
    print(ans/N)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[68]:


N, K = map(int, input().split())


# In[71]:


ans = 0
for i in range(1,N+1):
    ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N


# In[72]:


print(ans)


# In[ ]:

Submission status: Runtime Error

Solution code:
import math
n,k = map(int, input().split())
th={}
for i in range(0,math.ceil(math.log(10,2))+1):
    th[i]=0
for i in range(0,n):
    num = n-i
    cnt=0
    while 1:
        if num>=k:
            th[cnt]+=1
            break
        else:
            num*=2
            cnt+=1
ans = 0
for key in th:
    ans+=th[key]/(2**key)
print(ans/n)

Submission status: Runtime Error

Solution code:
def con(first, point):
    if first >= point:
        return 0
    i = 0
    c = first
    while (c <= point):
        c = c * 2
        i = i + 1
    return i

def co(first, m):
    i = first
    res = 1
    while i < m:
        res = res * 2
        i = i + 1
    return res

line = [int(x) for x in input().split(' ')]

dice = line[0]
win = line[1]

vals = [con(x, win) for x in range(1, dice + 1)]
pm = vals[0]


per = pow(vals[0], 2) * dice
perc =[co(x, vals[0]) for x in vals]
print(sum(perc) / per)

Submission status: Runtime Error

Solution code:
from fractions import Fraction

N, K = map(int, input().split())
ans = 0

flag = True
score = 1
times = 0
while flag:
  times += 1
  score *= 2
  if score >= K:
    flag = False

for i in range(1, N+1):
  ans += Fraction(1, N) * (Fraction(1, 2) ** times)
  times -= 1

print(float(ans))

Submission status: Runtime Error

Solution code:
from math import log
from math import ceil
while(1):
    ans=0
    n,k=map(int,input().split())
    for i in range(1,n+1):
        a=ceil(k/i)
        x=ceil(log(a,2))
        ans+=0.5**x
    print(ans/n)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> 	pii;
typedef long long 		ll;
typedef vector<int> 	vi;
typedef long double ld;
#define PI 				3.14159265
#define int				long long
#define f 				first
#define s 				second
#define pb 				push_back
#define mtup 			make_tuple
#define nl 				'\n'
#define FLASH 			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap 		priority_queue<ll>
#define minheap 		priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = 1e18 + 1;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 55;
ll modpow(ll a,ll b,int mod = LLONG_MAX) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}

signed main(){
	FLASH
	int n, k;
	cin >> n >>k;
	ld prob = 0;
	for (int i = 1; i <= min(k - 1, n); i++){
		int pp = ((int)(log2(k/i)) + 1);
		if (pp < 0) cout << pp << nl;
		ld hea = (double)1/(modpow(2,pp,inf));
		hea *= ((double)1/n);
		prob += hea;
	}
	if (k <= n){
		prob += (double)(n- (k-1))/n;
	}
	cout << setprecision(15) << prob;
	return 0;
}

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
X_list =[]
if N<K:
    pro = 0
    for n in range(N):
        if K % (2*(n+1))==0:
            X_list.append(K / (2*(n+1))-1)
        else:
            X_list.append( K // (2*(n+1))+1)
    X_max = max(X_list)
    for _ in range(len(X_list)):
        X_list[_] =X_max-X_list[_]
        X_list[_] =2**X_list[_]

    pro += sum(X_list)/(N*2**X_max)

    print(pro)

else:
    pro = (N-K+1)/N
    
    for n in range(K-1):
        if K % (2*(n+1))==0:
            X_list.append( K / (2*(n+1))-1)
        else:
            X_list.append( K // (2*(n+1))+1)

    X_max = max(X_list)
    for _ in range(len(X_list)):
        X_list[_] = X_max - X_list[_]
        X_list[_] = 2 ** X_list[_]
    pro += sum(X_list)/(N*2**X_max)

    print(pro)

Submission status: Runtime Error

Solution code:
import math
n,k = map(int, input().split())

for i in range(0,math.ceil(math.log(10,2))+1):
    th[i]=0
for i in range(0,n):
    num = n-i
    cnt=0
    while 1:
        if num>=k:
            th[cnt]+=1
            break
        else:
            num*=2
            cnt+=1
ans = 0
for key in th:
    ans+=th[key]/(2**key)
print(ans/n)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int N; long double K; cin >> N >> K;
    long double sum = 0;
    for(int i=1; i<=N; i++){
        if(K/i <= 1){
            sum += 1.0;
        }else{
            int necessary = log2(K/i);
            necessary += 1;
            long double p = 2;
            sum += 1.0/powl(p, necessary);
        }
    }
    cout << setprecision(12) << sum/N << endl;
}

Submission status: Runtime Error

Solution code:
r=0
if n < k:
    for i in range(1, n+1):
        r=r+(1/n)*0.5**math.ceil(math.log2(k/i))
    print(r)
else:
    r=1-(k/n)
    for i in range(1, k+1):
        r=r+(1/n)*0.5**math.ceil(math.log2(k/i))
    print(r)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
p=0
for i in range(N):
    #   print(i)
    if i+1 >= K:
        X =0
    else:
        X = math.ceil((math.log2(K/(i+1))))
        # X = round(math.log2(K-1/(i+1))+1)
        # print(math.log2(K-1/(i+1))+1)
        # print(math.log2(K/(i+1)))
        # print(round(math.log2(K/(i+1))))
        # print(X)
        # print(math.log2(K/(i+1)))
        # print(X)
    p +=(1/2)**X
p = p/N
print(p)

Submission status: Runtime Error

Solution code:
[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob += 1 / n * ((1 / 2) ** num)
    
print(prob)

Submission status: Runtime Error

Solution code:
s = input()
a, b = int(s[:2]), int(s[2:])

def func(i):
  if (i==0) | (i>12):
    return 'YY'
  else:
    return 'MM'
  
ans  = func(a) + func(b)
if (ans=='YYMM') | (ans=='MMYY'):
  print (ans)
elif ans=='MMMM':
  print ('AMBIGUOUS')
else:
  print('NA')

Submission status: Runtime Error

Solution code:
n, k = list(map(int, input().split(" ")))

ans = 0
ans1 = 0
flag = False
for i in range(n, 0, -1):

    if(i >= k):
        ans1 += 1
        continue

    if(flag == False):
        flag = True
        j = 1
        while(i**(j+1) < k): j += 1

        tmp = j
        ans += 1
    else:
        while(i**(j+1) >= k): j -= 1
        j += 1

        if(tmp != j):
            ans *= 2
            ans += 1
            tmp = j
        else: ans += 1

print((ans+ans1*2**j) / (n*2**j))

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
result = 0
count = math.ceil(K / 2 - 1)

for i in range(N):
    result += (1/2)**count
    count -= 1

print(result * (1/N))

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())
sum=0
for i in range(1,N+1):
  if i>=K:
    sum=sum+(1/N)
  else:
    sum=sum+(1/N)*((1/2)**(math.ceil(math.log2(K/i)))
print(sum)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N, K = map(int, input().split())
p = 0
dnms = []


def calc_p(n, c):
    return 1/n * pow(1/2, c)


def calc_dnm(n, c):
    return n * 2 ** c


def calc_lcm(ns):
    return reduce(lcm, ns, 1)


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


for i in range(1, N+1):
    score = i
    cnt = 0
    while score <= K:
        score *= 2
        cnt += 1
    dnms.append(calc_dnm(N, cnt))
    p += calc_p(N, cnt)

#print(p)

l = calc_lcm(dnms)
mlcls = [l/x for x in dnms]
print(sum(mlcls) / calc_lcm(dnms))

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())

ma = int(math.log2(k)) + 1
mi = int(math.log(k, n))

t = ma - mi + 1

ans = (2 / (2 ** mi) - 1 / (2 ** ma)) / n

print('{:.10g}'.format(ans))

Submission status: Runtime Error

Solution code:
[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob = prob + 1 / n * ((1 / 2) ** num)
    
print(prob)

Submission status: Runtime Error

Solution code:
n, k = list(map(int, input().split(" ")))

ans = 0
ans1 = 0
flag = False
for i in range(n, 0, -1):
    if(k % n == 0): count = k // n
    else: count = k // n + 1

    if(i >= k):
        ans1 += 1
        continue

    if(flag is False):
        flag = True
        j = 1
        while(i**(j+1) < k): j += 1

        tmp = j
        ans += 1
    else:
        while(i**(j+1) >= k): j -= 1
        j += 1

        if(tmp != j):
            ans *= 2
            ans += 1
            tmp = j
        else: ans += 1

print((ans+ans1*2**j) / (n*2**j))

Submission status: Runtime Error

Solution code:
//#include <bits/stdc++.h>

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>

using namespace std;


int main() {
//   int N, K;
//   cin >> N >> K;
//   vector<int > S(4);
//   for(int i =0; i<4; i++){
//       cin >> S.at(i);
//   }
    float N, K, score;
    float prob, tmp;
    cin >> N >> K;
    prob = 0;
    for (int i =1; i<N+1;i++){
        tmp = 1/N;
        score = i;
        while(score < K){
            tmp = tmp/2;
            score = score*2;

        }
        prob += tmp;

    }
    cout << prob << endl;

}

Submission status: Runtime Error

Solution code:
# coding: utf-8

import sys
import math
input = sys.stdin.readline

# N = int(input())
# L = [int(x) for x in input().split()]
N, K = map(int, input().split())
# S = input()

max_pow = int(math.log2(K) + 0.9)

one_half = [0] * (max_pow + 1)
one_half[0] = 1
for i in range(1, max_pow + 1) :
    one_half[i] = one_half[i - 1] * 0.5

ans = 0
for i in range(1, N + 1) :
    pow_num = math.ceil(math.log2(K / i))
    
    if pow_num <= 0 :
        ans += 1
    else :
        ans += one_half[pow_num]
        
print(ans / N)

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())
limit = 1 / n
ans = 0
for x in range(1 , n + 1):
    num = math.pow(2, -1 * math.ceil(math.log(k / x, 2)))
    num = num / n
    if num > limit:
        num = limit
    ans = ans + num
    if ans >= 1:
        break
print("{:.12
f}".format(ans))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
for i in range(1, 1+n):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, len(t2)+1):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
print(r/n)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
kaizyo = (K-1) // 2
print(kaizyo)
all_sum = 0
for n in range(0,N):
    all_sum = all_sum + 1/N * ((1/2)**(kaizyo-n))
    print('-'*20)
    print(1/N)
    print((1/2)**(kaizyo-n))
    print(1/N * (1/2)**(kaizyo-n) )
print(all_sum)

Submission status: Runtime Error

Solution code:
[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 1:
        num = 1
    prob = prob + 1 / n * ((1 / 2) ** num)
    
print(prob)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
un = 0
aa = 1
sum = 0
k = 0
while k <= K:
  un = un + 1
  k = 2 ** un

sum = N * 2 ** un
h = (2 ** N) -1
print(h / sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
N ,K=map(int ,raw_input().split())
 
C = []
for i in range(N):
    C.append(int(math.ceil(np.log2(K)-np.log2(i+1))))
P = 0.000
C.sort()
k =C[0]
t = 0
p = 0.5**(k-1)
#print(C)
for n in C:
    if k != n:
        p2 = P*t/(2**(n-k))
        p=p*/(2**(n-k))
        P+=p2
        k=n
        t = 1
    else:
        t +=1
P+=p/2*t
print (P/N)

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())

ma = int(math.log2(k)) + 1
mi = int(math.log(k, n))

t = ma - mi + 1

ans = (2 / (2 ** mi) - 1 / (2 ** ma)) / n

print(ans)

Submission status: Runtime Error

Solution code:
import math

N,K = list(map(int,input().split()))
odd = 0

if N >= K:
  odd += (N-K+1)/N
  for i in range(K-1):
    if (math.log2(K/i))%1==0:
      odd += i/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/i))+1))
else:
  for i in range(N):
    if (math.log2(K/i))%1==0:
      odd += i/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/i))+1))
      
print(odd)

Submission status: Runtime Error

Solution code:
[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob = prob + 1 / n * ((1 / 2) ** num)
    
print(prob)

Submission status: Runtime Error

Solution code:
from decimal import*
getcontext().prec = 28

n, k = map(int, input().split())

preans = 0

cs = 1 #2の-cs乗との比較
for i in range(n):
    if n - i < k:
        while float(Decimal(1) /Decimal(2**cs)) >= float(Decimal(n - i) / Decimal(k)):
            cs = cs + 1
        preans = preans + float(Decimal(1) / Decimal(2**cs))
    else:
        preans = preans + 1

ans = preans / Decimal(n)
print(ans)

Submission status: Runtime Error

Solution code:
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
  print(1)
  exit()
while tempb > 1:
  if tempb <= inputa[0]:
    tempa.append(inputa[0] - tempb + 1)
  else:
    tempa.append(0)
    
  tempb /= 2

i = 1
tempc.append(tempa[0])
while i <= len(tempa):
  tempc.append(tempa[i] - tempa[i - 1])
  i += 1

for i, num in enumerate(tempc):
  res += num / inputa[0] / (2 ** i)

print(res)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(list(map(deno, np.arange(1,N+1)))) / N
print(pro)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())


def cc(n):
    i = 
    while True:
        if K <= (n * (2 ** i)):
            return i
        i += 1


A = 0
for n in range(1, N+1):
    A += 1.0 / N * (0.5 ** cc(n))
print(A)

Submission status: Runtime Error

Solution code:
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
  print(1)
  exit()
while tempb > 1:
  if tempb <= inputa[0]:
    tempa.append(inputa[0] - tempb + 1)
  else:
    tempa.append(0)
    
  tempb /= 2

i = 1
tempc.append(tempa[0])
while i <= len(tempa):
  tempc.append(tempa[i] - tempa[i - 1])
  i += 1

for i, num in enumerate(tempa):
  res += num / inputa[0] / (2 ** i)

print(res)

Submission status: Runtime Error

Solution code:
import math
N, K = input().split(" ")
N, K = int(N), int(K)
P = 0
if (N < K):
  for n in N:
    P += 1/(N*math.ceil(math.log2(K)-math.log2(n)))
else:
  for n in K:
    P += 1/(N*math.ceil(math.log2(K)-math.log2(n)))
  P += (K-N)/N
print(P)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

r = 0
def func(n):
	c, t = 0, n
	while t <= K:
		t <<= 1
		c += 1
	#return (1 / 2) ** c
	return c
"""
for n in range(N):
	#r += [func(n)]
	r += 2 ** n
	#print(r)
"""

base = func(1)

r = int("1" * (base - 1), 2)
#print(r)

print(r * ((1 / 2) ** base) / N)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N, K = map(int, input().split())
p = 0
dnms = []


def calc_p(n, c):
    return 1/n * pow(1/2, c)


def calc_dnm(n, c):
    return n * 2 ** c


def calc_lcm(ns):
    return reduce(lcm, ns, 1)


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


for i in range(1, N+1):
    score = i
    cnt = 0
    while score <= K:
        score *= 2
        cnt += 1
    dnms.append(calc_dnm(N, cnt))
    p += calc_p(N, cnt)

print(p)

l = calc_lcm(dnms)
mlcls = [l/x for x in dnms]
print(sum(mlcls) / calc_lcm(dnms))

Submission status: Runtime Error

Solution code:
import math

n,k = list(map(int,input().split()))
ans=0
for i in range(1,n+1):
    ans+=1/2**(math.ceil(math.log(k//i,2)))

ans/=n

print(ans)

Submission status: Runtime Error

Solution code:
import math
N, K = input().split(" ")
N, K = int(N), int(K)
P = 0
if (N < K):
  for n in N:
    P += 1/(N*math.ceil(math.log2(K)-math.log2(n)))
else:
  for n in K:
    P += 1/(N*math.ceil(math.log2(K)-math.log2(n)))
  P += (K-N)/N
print(K)

Submission status: Runtime Error

Solution code:
import numpy as np

n, k = map(int, input())
ans = 0

for i in range(1, n):
  if i >= k:
    ans += 1.0 / n
    
  ans += np.power(1 / 2, np.ceil(np.log2(k / i))) / n
  
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
ans = 0
 for i in range(n):
    if i => k:
      ans += float(1/n)
    else:
      c = i
      d=0
      while c<k:
        c = c*2
        d+=1
      ans +=float(1/n*(2**d))
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import numpy as np

N, K = map(int, input().rstrip().split(' '))

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
cumprod = np.cumprod([0.5] * int(c[0]+1))
print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())

ma = int(math.log2(k)) + 1
mi = int(math.log(k, n))

t = ma -mi + 1

ans = (2 ** n - 1) / (n * 2 ** ma)

print(ans)

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())

S=0

if N>K:
    for i in range(1,N+1):   
        if i>=K:
            S+=1/(2*N)
        else:    
            S+=(1/N)*((1/2)**(int(math.log2(K/i)+1)))
else:
    S+=(1/N)*((1/2)**(int(math.log2(K/i)+1)))
print(S)

Submission status: Runtime Error

Solution code:
import math
N, K = (int(i) for i in input().split())

pow_base = math.floor(math.log((K-1),2)) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log((K-1) // i, 2)) + 1
        res += 2 ** (pow_base - power)
print(res / base)

Submission status: Runtime Error

Solution code:
import math

N,K = map(int, input().split())

p = 0.0

if K>N:
    tp = 0.0
    for i in range(1,N+1):#1~N
        #deme i
        tp += 0.5**math.ceil(math.log2(K/i))
    tp = tp / N
    print(tp)
else:
    p = (N-K+1.0)/N#No coin
    tp = 0.0
    for i in range(1,K):#1~K-1
        #deme i
        tp += 0.5**math.ceil(math.log2(K/i))
    tp = tp / (K-1.0)
    print(p+(1.0-p)*tp)

Submission status: Runtime Error

Solution code:
import math
N, K = (int(i) for i in input().split())

pow_base = math.floor(math.log2((K-1))) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log2((K-1) // i)) + 1
        res += 2 ** (pow_base - power)
print(res / base)

Submission status: Runtime Error

Solution code:
    N, K = map(int,input().split())
    ans = 0.0
    for i in range(1,N+1,1):
        count = 0
        tmp = i
        if tmp < K:
            while True:
                tmp *= 2
                count += 1
                if tmp>K:
                    break
    ans += float(1/N)*(0.5**count)
    print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input())
# N ,K = 100000, 5

def min_v(x, k):
    v=1.0
    while v>x/k:
        v /= 2
    return v

V = 0
for n in range(1, N+1):
    V += min_v(n, K)

print('{:.16f}'.format(V/N))

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if int(Y) * 10 % 10 !== 0:
        Y_int = int(Y) + 1
      else:
        Y_int = int(Y)
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
ans=float(0)
for i in range(n):ans+=(0.5**(int(k**0.5)+1-i))/n
print(ans)

Submission status: Runtime Error

Solution code:
import math
N, K = tuple(map(int, input().split()))
base = 1 / N

if N == K:
  print(base)
s = 0
for i in range(1, N+1):
  n = math.ceil(math.log2((K-1)/i))
  print(i, n)
  s += base * (0.5 ** n)
print(s)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
if n<k:
    p=0
    for i in range(1,n+1):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
else:
    p=(n-k+1)/n
    for i in range(1,k):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
Z = []
a = 2 ** (math.floor(K ** (1/N))) * N / 2
for i in range(N):
  Z += [1/a]
  a = a * 2
sum = 0
for b in Z:
  sum += b
print(sum)

Submission status: Runtime Error

Solution code:
import math

N,K = map(int,input().split())

def prob_wins(x,k):
    if x>=k:
        return 1
    return 0.5**math.ceil(math.log2(k/x))

ans = 0
for i in range(1,N+1):
    ans += prob_wins(i,K)
    # print(i,prob_wins(i,K))
print(ans/N)

Submission status: Runtime Error

Solution code:
a, b = (int(_) for _ in input().split())  
res = float(sum([(1/2 ** (math.ceil(int(b/i)**(1/2)))) if i < b else 1 for i in range(1,a+1)]) / a)
print(res)

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().split())
p = 1 - K/N
for i in range(1, K):
  n = floor(math.log(N/i, 2))
  p += 1/N * (1/2 ** n)
print(p)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
p_lis = []
import math
for x in range(1,n+1):
    power = -((-math.log2(k//x))//1)
    p_lis.append(((1/2)**power)*(1/n))
print(sum(p_lis))

Submission status: Runtime Error

Solution code:
import math

N,K = map(int, input().split())

p = 0

if K>N:
    tp = 0
    for i in range(1,N+1):
        #deme i
        tp += 0.5**math.ceil(math.log2(K/i))
    tp = tp / N
    print(tp)
else:
    p = (N-K+1)/N#No coin
    tp = 0
    for i in range(1,K):
        #deme i
        tp += 0.5**math.ceil(math.log2(K/i))
    tp = tp / (K-1)
    print(p+(1-p)*tp)

Submission status: Runtime Error

Solution code:
from math import *

n, k = [int(item) for item in input().split()]
ans = 0
for p in range(1, n + 1):

    if p >= k:
        ans += 1;
    else:
        x = ceil(log2(k / p))
        ans += 1.0 / (1 << x);
print(ans / n)

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().strip().split(' '))

ans = 0
count = int(math.log2(K)-math.log2(N))
if count < 0:
    count = 0
val = 2**count

for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val

print(ans/N)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n


for i in range(1,min(k,n+1)):
    temp = 1/n
    tval = k/i
    p = int(math.log2(tval))+1

    ans +=temp*(0.5**p)
print(ans)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]

def l2c(x):
	c = 1 / n
    while x < k:
		x = x * 2
        c = c / 2
    return c
  
print(sum([l2c(i) for i in range(1, n+1)])

Submission status: Runtime Error

Solution code:

from math import *




n,k=map(int,input().split(" "))

ans=0

oye=int(ceil(log2(k)))

how=min(n,k)
f=max(0,n-how)

dd=((2**how)-1)/(2**oye)

sa=(dd+f)/n

print ("{0:.20f}".format(sa))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
ans = max((n - k + 1) / n, 0)
for a in range(1, min(k, n + 1)):
    ans += 0.5 ** (k // a).bit_length() / n
print(f'{ans:.12f}')

Submission status: Runtime Error

Solution code:
S = input()
s_1 = int(S[:2])
s_2 = int(S[2:])


def month(n):
    if 0 < n < 13:
        return 0
    else:
        return 1
def year(n):
    if 0< n:
        return 0
    else:
        return 1

if month(s_1) == 0:
    if month(s_2) == 0:
        print("AMBIGUOUS")
    elif year(s_2) == 0:
        print("MMYY")
    else:
        print("NA")
elif year(s_1) == 0:
    if month(s_2) == 0:
        print("YYMM")
    else:
        print("NA")
else:
    print("NA")

Submission status: Runtime Error

Solution code:
import math
n,k = map(int,input().split())

ret=0

for i in range(1,n+1):
    p=math.ceil(math.log2(k/i))
    p=p if p>0 else 0
    ret+=math.pow(0.5,p)/n

print(ret)

Submission status: Runtime Error

Solution code:
N,K=map(int, input().split())
#N,K=100000, 100000

l=[]
for i in range(1,N+1):
    n=0
    while i =< K:
        i *= 2
        n+=1
    l.append(1/N * (1/2)**n)

print(str(sum(l))[:14])

Submission status: Runtime Error

Solution code:
S = int(input())

before = S % 100
after = S //100

if after == 0 or before == 0:
  print("NA")
elif after >31 and before > 31:
  print("NA")
elif before <= 12 and after <= 12:
  print("AMBIGUOUS")
elif before <= 12 and after > 12 :
  print("YYMM")
elif before > 12 and after <= 12:
  print("MMYY")
else:
  print("NA")

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().split())
p = 0

for i in range(1, min(K, N + 1)):
    print(math.ceil(math.log2(K / i)))
    p += 2 ** (-math.ceil(math.log2(K / i)))

p += max(0, N - K + 1)
print(p / N)

Submission status: Runtime Error

Solution code:
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:03 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import log2

n,k = (int(num) for num in input().split())
p = 1/n
ans = 0.0

if n >= k:
    ans += p * (n-k+1)
    for i in range(1,k):
        ans += p*(1/2)**(int(log2(k/i))+1)
        
else:
    for i in range(1,n+1):
        ans += p*(1/2)**(int(log2(k/i))+1)
        
print(ans)

Submission status: Runtime Error

Solution code:
import math
n,k = map(int,input().split())
twos = [1]
i = 0
while 2*twos[i] <= 10**5:
    twos.append(twos[i]*2)
    i += 1

ans = 0
for i in range(1,n+1):
    temp = 0
    while twos[temp] * i <= k-1:
        temp += 1
    ans += 1/n * 1/twos[temp]
print(ans)

Submission status: Runtime Error

Solution code:


from math import *




n,k=map(int,input().split(" "))

ans=0
power=1

while(power<k): power=power<<1


for i in range(1,n+1):
	if(i>=k):
		ans+=(1/n)
	else:
		now=(1/n)
		now*=(1/power)
		power=power>>1
		ans+=now
print(ans)