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, ceil

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

res = 0
for i in range(1, min(n+1, k)):
##    print(k-i, ceil(log(k//i, 2)))
    res += (0.5 ** ceil(log(k//i, 2)))
    
if n >= k:
    res += (n-k+1)
print(f'{res/n:.9f}')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K - 1:
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2*cnt))

print(calc)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K-1
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2*cnt))

print(calc)

Submission status: Runtime Error

Solution code:
N, K = map(int, input())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K-1
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2**cnt))

print(calc)

Submission status: Runtime Error

Solution code:
N, K = map(int, input())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K-1
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2*cnt))

print(calc)

Submission status: Runtime Error

Solution code:
N, K = map(int, input())
 
calc = []
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K-1
    tmp*=2
    cnt+=1
  calc.append((1/N) * (1/(2*cnt)))

print(sum(calc))

Submission status: Runtime Error

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

calc = []
for i in range(1, N+1):
  dice = i
  result = 0
  count = 0
  while result <= K-1
    dice+=dice*2
    count+=1
  calc.append(1/N*(1/2)*count)

print(sum(calc))

Submission status: Runtime Error

Solution code:
N, K = map(int, input())
 
for i in range(N):
  dice = i+1
  result = 0
  calc = []
  count = 0
  while result <= K-1
    dice+=dice*2
    count+=1
  calc.append(1/N*(1/2)*count)

print(sum(calc))

Submission status: Runtime Error

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

for i in range(N):
  dice = i+1
  result = 0
  calc = []
  count = 0
  while result <= K
    dice+=dice*2
    count+=1
  calc.append(1/N*(1/2)*count)

print(sum(calc))

Submission status: Runtime Error

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

import math
sums = 0
for i in range(1,N+1):
    num=int(math.log(K//i,2)+1)
#     if num>int(num):
#         num=int(num)+1
    if i>K-1:
        sums +=(1/N)
    else:
        sums += 1/(N * math.pow(2,num))

print(sums)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

for i in range(1, n + 1):
    c = math.ceil(math.log2(k / i))
    res += (1 / n) * (0.5 ** c)

print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())

P=0
for i in range(1,N+1):
    if i < K:
        p = float((1/N)*(1/2)**np.ceil(np.log2(K/i)))
    elif  i > K:
        p = float(1/N)
    P += p
print(P)

Submission status: Runtime Error

Solution code:
s=input()

if int(s[:2])>12:
  if int(s[2:])<=12 and int(s[2:]) >0:
    print("YYMM")
  else:
    print("NA")
elif int(s[:2])<=12 and int(s[:2])>0:
     if int(s[2:])<=12 and int(s[2:])>0 :
       print("AMBIGUOUS")
     elif int(s[2:])>12:
       print("MMYY")
     else:
       print("NA")
else:
  print("NA")

Submission status: Runtime Error

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

for i in range(1, n):
  mul = 0
  
  while k > i * 2** mul:
    mul += 1
    
  pb += (0.5 ** mu) / n
print(pb)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

res = 0
for i in range(1, n+1):
    a = k / i
    b = format(math.ceil(a) - 1, 'b')
    num = 0 if b == '0' else len(b)
    res +=  (1/n) *  (1/2)**num
print(res)

Submission status: Runtime Error

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

S = 0

for i in range(N):
  S += ((1/N)*(2**((-1)*max(0, math.ceil(math.log2((K-1)/(i+1)))))))

print(S)

Submission status: Runtime Error

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

S = 0

for i in range(N):
  S += (1/N)*max(math.floor(math.log2((K-1)/N)),1)

print(S)

Submission status: Runtime Error

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

S = 0

for i in range(N):
  S += (1/N)*math.floor(math.log2((K-1)/N))

print(S)

Submission status: Runtime Error

Solution code:
n = int(input())
T = []
for _ in range(n-1):
    T += [list(map(int, input().split()))]
T.sort()
P = [0]+[-1]*(n-1)
b = n-1
while b > 0:
    for u, v, w in T:
        pu, pv = P[u-1], P[v-1]
        if (pu >= 0) & (pv < 0):
            P[v-1] = (pu+(w%2))%2
            b -= 1
        if (pv >= 0) & (pu < 0):
            P[u-1] = (pv+(w%2))%2
            b -= 1
for p in P: print(p)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
p = 0.0
for i in range(1,n+1):
    if i < k:
        x = math.ceil(math.log((float(k) / float(i)), 2))
        print "---"
        print x
        print i * (2 ** x)
        p += (float(1) / float(n)) * ((0.5) ** x)
    else:
        p += (float(1) / float(n))

print p

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
ans = 0
for i in range(1, N+1):
  if K%i == 0:
    p = i * (1/n)*(1/2)**(K//i)
  else:
    p = i * (1/n)*(1/2)**(K//i+1)
  ans += p
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
log = 18
dp = [[0 for i in range(K+1)] for j in range(log)]
for i in range(1,N+1):
    dp[0][i] = 1/N
if  K%2 == 0:
    lim = K//2 - 1
else:
    lim = K//2
for i in range(1,log):
    j = 2
    while j <= K-1:
        dp[i][j] = dp[i-1][j//2] / 2
        j += 2
    dp[i][K] = dp[i-1][K] + sum(dp[i-1][lim+1:K-1])/2
print(dp[log-1][K])

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
p = 0
for i in range(1,n+1):
  tmp = 1
  while i * temp < k:
    temp *= 2
  p += 1/temp
print(p/n)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
p = 0
for i in range(1,num):
  tmp = 1
  while i * temp < k:
    temp *= 2
  p += 1/temp
print(p/n)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
p = 0
for i in range(1,num):
  tmp = 1
  while i * temp < k:
    temp *= 2
  asn += 1/temp
print(p/n)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,k = map(int,input().split())
	ans = frac(float(0))
	scala = frac(1,n)
	for i in range(1,n+1):
		if(i>k):
			ans += frac(float(1)) * scala
		else:
			ans += frac(1,2**(math.ceil(math.log2(k/i)))) * scala
	print(float(ans))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,k = map(int,input().split())
	ans = frac(float(0))
	scala = frac(1,n)
	for i in range(1,n+1):
		ans += frac(1,2**(math.ceil(math.log2(k/i)))) * scala
	print(float(ans))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Runtime Error

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

dic = {}
i = 0
while (2 ** i) <= (10 ** 5):
    dic[i] = 0
    i += 1

for i in range(1, N+1):
    cnt = 0
    while i * (2 ** cnt) < K:
        cnt += 1
    dic[cnt] += 1

ans = 0
for k, v in dic.items():
    if v > 0:
        ans += v * (0.5 ** k) / N

print(ans)

Submission status: Runtime Error

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

dic = {}
i = 0
while (2 ** i) <= (10 ** 5):
    dic[i] = 0
    i += 1

for i in range(1, N+1):
    cnt = 0
    while i * (2 ** cnt) < K:
        cnt += 1
    dic[cnt] += 1

ans = 0
for k, v in dic.items():
    if v > 0:
        ans += v * (0.5 ** k)

ans /= N
print(ans)

Submission status: Runtime Error

Solution code:
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
    	if math.log2(k//i) == int(math.log2(k//i)):
      		x = int(math.log2(k//i))
    	else:
      	x = int(math.log2(k//i)) + 1
  	else:
     	x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

Submission status: Runtime Error

Solution code:
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if (k/i) == (k//i):
    if math.log2(k//i) == int(math.log2(k//i)):
      x = int(math.log2(k//i))
    else:
      x = int(math.log2(k//i)) + 1
  else:
     x = int(math.log2(k//i)) + 1
  res += (1/n) * (0.5 ** x)
print(res)

Submission status: Runtime Error

Solution code:
import math
N,K=(int(x) for x in input().split())
ans=0
for i in range(1,N+1):
  ans+=((1/2)**math.ceil(math.log2(k*1.0/i)))/i
print(i)

Submission status: Runtime Error

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

pi = 0
for i in range(1,n+1):
  need = math.ceil(math.log(k/i,2))  
  if need > 0:
    pi += (1/2) ** need
  else :
    pi +=1      
print(pi/n)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
for i in range(1,n+1):
	a = i
	p = 1/n
	while a < k:
    	a = a*2
    	p = p*0.5
  	pro[i] = p
  
print(sum(pro))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
for i in range(1,n+1):
  a = i
  p = 1/n
  while a < k:
    a = a*2
    p = p*0.5
  pro[i] = p
  
print(sum(pro))

Submission status: Runtime Error

Solution code:
import math as m
n,k=map(int,input().split())
p=0
for i in range(1,k):
  r=m.ceil(m.log(k/i,2))
  p+=1/(2**r)
for _ in range(K,n+1):
  p+=1
print(p/n)

Submission status: Runtime Error

Solution code:
import math as m
n,k=map(int,input().split())
p=0
for i in range(1,k):
  r=m.ceil(m.log(k/i,2))
  p+=1/(2**r)
for _ in range(K,N+1):
  p+=1
print(p/n)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
p = 0
for i in range(1, n+1):
    sum_ = i         range()
    j = 0
    while True:
        if sum_ >= k:
            break
        sum_ *= 2
        j += 1
    q = 1
    for x in range(j):
        q *= 0.5
    p += q
p /= n
print(p)

Submission status: Runtime Error

Solution code:
# main
N, K = R()
ans = 0
for i in range(N):
    s = i + 1
    deno = N
    while s < K:
        s *= 2
        deno *= 2
    ans += 1/deno
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
p = 0.0
if N >= K:
    p1 = (N-K+1)/N
    p2 = 1.0
    p += p1
    temp = 0.0
    for i in range(1, K): # 1 to K-1
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p2 *= temp*(1/N)
    p += p2
else:
    temp = 0
    for i in range(1, N+1): # 1 to N
        n = int(log2(K-1)-log2(i))+1
        temp += (0.5)**n
    p = temp*(1.0/N)
print(p)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
k = int(input())
ans = np.zeros(n)

for i in range(n):
    ans[i] = 1.0

for i in range(n):
    tmp = i+1
    while(tmp < k):
        ans[i]*=0.5
        tmp*=2


print(np.sum(ans)/n)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
import math as ma
a = []
for i in range(1,N+1):
    k = ma.ceil(ma.log2(K/i))
    if i < K:
        a.append(k)
    else:
        a.append(0)
m = max(a)
s = sum([2**(m-a[i]) for i in range(len(a))])
print(s/(N*(2**m)))

Submission status: Runtime Error

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, K = map(int, input().split())
    ans = 0.0
    for i in range(1, N + 1):
        if i < K:
            num = 0
            while i < K:
                i *= 2
                num += 1
            ans += (1 / (2**num)) * (1 / N)

        else:
            ans += 1 / N

    print(f"{ans:.10f}")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

ans = 0

"i点の時、k点以上になるためにはlog2(k/i)回連続で表を出す必要がある"
for i in range (1:n + 1):
  if i < k:
    omote = math.ceil(math.log(k/i, 2))
    ans += (1/2) **(omote)
  else :
    ans += 1
print(ans/n)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
l_list=[]
r_list=[]

for i in range(m):
    l,r=map(int,input().split())
    l_list.append(l)
    r_list.append(r)

n_card=min(r_list)-max(l_list)+1

if n_card<=0:
    print(0)
else:
    print(n_card)

Submission status: Runtime Error

Solution code:
import math

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

l = []
for i in range(n):
    if i <= k:
        m = math.ceil(math.log2(k/(i+1)))
        l.append(1/2**m)
    else:
        l.append(1)

print(1/n*sum(l))print(1/n*sum(l))

Submission status: Runtime Error

Solution code:
def solve():
	diceSurfaces, winBorder = [int(x) for x in input().split()]
	diceProbability = (1 / diceSurfaces)
	ans = 0
	for score in range(1, diceSurfaces + 1):
		if score >= winBorder:
			ans += diceProbability
			continue 
		needNum  = math.ceil((winBorder) / score)
		needWins = math.ceil(math.log2(needNum))
		ans += diceProbability * ((1/2) ** needWins)
	print(ans)
solve()

Submission status: Runtime Error

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


for i in range(n):
    k = coin(i, k)
    sum += (1/n) * ((0.5) ** k)

print(sum)


def coin(j,k):
    point = j
    count = 0
    while k <= point:
        point = point * 2
        count += 1
    return count

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
bosu = [1]*N
for i in range(1:N+1):
    point = i
    while i < K:
        point *= 2
        bosu[i-1] *= 2

print(N/sum(bosu))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
p=float(0.0)
for i in range(1,n+1):
  divide=float(k/i)
  howmany=max(math.ceil(math.log(divide,2)),0)
  p+=1/(n*(2**howmany))
print(p)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
p=float(0)
for i in range(1,n+1):
  divide=float(k/i)
  howmany=math.ceil(math.log(divide,2))
  p+=1/(n*(2**howmany))
print(p)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
p=float(0)
for i in range(1,n+1):
  divide=float(k//i)
  howmany=math.ceil(math.log(divide,2))
  p+=(1//n)*(0.5**howmany)
print(p)

Submission status: Runtime Error

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

prob = 0.0
potencias = [1]
i = 2
while i < 100001:
    potencias.append(i)
    i *= 2

# print potencias
for i in xrange(1, N+1):
    if i < K:
        j = 0
        while potencias[j]*i < K:
            j += 1
        p = 1.0/(N*1.0)
        p *= (0.5**j)
        prob += p
    else:
        prob += 1.0/(N*1.0)
    
print prob

Submission status: Runtime Error

Solution code:
def dfs(node, distance):
    for next_node, edge_size in G[node]:
        if ans[next_node] == -1:
            ans[next_node] = ((distance+edge_size) % 2)
            dfs(next_node, distance+edge_size)


N = int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])

ans = [-1]*N
dfs(0, 0)
print(*ans, sep='\n')

Submission status: Runtime Error

Solution code:
#input = raw_input

res = None
G = None

def dfs(jibun_v, p, jibun_c):
    global res
    global G

    res[jibun_v] = jibun_c
    #print(jibun_v, p, jibun_c)

    tonari_nodes = G[jibun_v]
    for tonari_v, w in tonari_nodes:
        #if tonari_v == p or res[tonari_v] != -1:
        if tonari_v == p or res[tonari_v] != -1:
            continue

        if w % 2 == 0:
            tonari_c = jibun_c
        else:
            tonari_c = 1 - jibun_c

        dfs(tonari_v, jibun_v, tonari_c)
    

def main():
    N= int(input())

    global G
    G = [[] for _ in range(N)]

    for i in range(N-1):
        u, v, w = map(int, input().split(" "))
        u -= 1
        v -= 1
        w = w % 2
        G[u].append([v, w])
        G[v].append([u, w])

    global res
    res = [-1 for _ in range(N)]
    
    jibun_v = 0
    p = -1
    jibun_c = 0
    dfs(jibun_v, p, jibun_c)

    for i in range(N):
        print(res[i])

main()

Submission status: Runtime Error

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

import math
import decimal

x = decimal.Decimal(0)

for i in range(n):
    e = math.floor(math.log2(k//(i+1)))+1
    print(e)
    x += decimal.Decimal(1/(n*(2**e)))
print(x)

Submission status: Runtime Error

Solution code:
from math import log2

def calProb(dice, K):
    time = log2(K)
    prob = 0
    base = 1/dice
    count = 0
    for i in range(1,dice+1):
        temp = base
        now = i
        while now < K:
            now *= 2
            temp *= 0.5
        prob += temp
        count += 1
    return prob + ((count - i)/dice)


inputs = list(map(float,input().split(' ')))[:2]
dice = inputs[0]
K = inputs[1]
probabilty = calProb(dice, K)
print(probabilty)

Submission status: Runtime Error

Solution code:
#coding: utf-8
#a, b = map(int, input().split())
#a, b, c, x = map(int, [input() for i in range(4)])

n, k = map(int, input().split())
sum = 0.0
a = 0.0

for i in range(n):
    i += 1
    a = (k / 2.0) - i
    sum += (1.0 / n) + ((1.0 / 2.0) ** a)

print(sum / 10.0)

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().split())
pro = 0
for score in range(N+1):
    a = math.floor(math.log(K,score))
    pro += 1/N * 0.5**a
print(pro)

Submission status: Runtime Error

Solution code:
from math import log2, ceil

ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
    
print(ans / (N * 2 ** max_pow))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
proba = 0
if K == 1:
    print(1)
else:
    for n in range(0, N+1):
        for ii in range(17):
            if n * (2 ** ii) >= K:
                proba += (1 / N) * (2 ** (-ii))
                break
            
	print(proba)

Submission status: Runtime Error

Solution code:
import math, decimal

memo = [1,2,4,8,16,32,64,128,256,512,1024,2048]
def twopow(f):
    if len(memo) < f:
        return memo[f]
    else:
        repeat = f - len(memo) + 1
        for _ in range(repeat):
            memo.append(memo[len(memo)-1]*2)
        return memo[f]

n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    x = math.ceil(math.sqrt(k/i)) if k > i else 0
    per += 1/twopow(x)

print(per/n)

Submission status: Runtime Error

Solution code:
def pow2(n):
	res = 1
	for i in range(0, n):
		res *= 2
	return res

counter = [0]
N, K = map(int, raw_input().split())
for i in range(1, N+1):
	m = i
	cnt = 1
	while m < K:
		m *= 2
		cnt += 1
	counter.append(cnt)
sum = 0L
for i in range(1, N+1):
	sum += long(pow2(count[1]-count[i]))
sum *= 10000000000
dv = long(N)*long(pow2(count[1]))

print sum
print dv

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
s = b
p = 0.0
for i in range(1,a+1):
	tmp = 1.0/a
	now = i
	while now < b:
		now = now*2
        tmp = tmp/2
	p = p+tmp
print(p)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
s = b
p = 0.0
for i in range(1,a+1):
	tmp = 1.0/a
	now = i
	while now < b:
		now = now*2
        tmp = tmp/2
	p = p+tmp
print(p)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	long double n, k,ans = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
	
	 ans += 1 / n * pow(0.5, (int)(log2(k/i)+1) * (k > i) );
	
	}
	cout << fixed << setprecision(12) <<ans << endl;
}

Submission status: Runtime Error

Solution code:
N,K=[int(i) for i in input().split()]
res=0
for i in range(1,N+1):
  res+=0.5**(math.ceil(math.log2(K/i)))
print(res/N)

Submission status: Runtime Error

Solution code:
from math import log2,ceil
N,K=map(int,(input().split()))
l=0
if N<K:
    for k in range(1,N+1):
        x=(0.5**ceil(log2(K/k)))/N
        l+=x
if N>=K:
    for k in range(1,K):
        x=(0.5**ceil(log2(K/k)))/N
        l+=x
    m=N-K/N 
print (l+m)

Submission status: Runtime Error

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

proba = 0
for i in range(1, N+1):
  x = i
  p = 1
  while x < K:
    p *= 0.5
    x *= 2
  proba += p/N
print(proba)

Submission status: Runtime Error

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

proba = 0.0

for i in range(1, N+1):
  x = i
  p = 1.0
  while x < K:
    p *= 0.5
    x += 1
  proba += p/N
  
print(proba)

Submission status: Runtime Error

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

proba = 0
for i in range(1, N+1):
  x = i
  p = 1
  while x < K:
    p *= 0.5
    x += 1
  proba += p/N

Submission status: Runtime Error

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

proba = 0
for i in range(1, N):
  x = i
  p = 1
  while x < K:
    p *= 0.5
    x += 1
  proba += p/N
  
print(proba)

Submission status: Runtime Error

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

proba = 0
for i in range(1, N):
  x = i
  p = 1
  while x < K:
    p *= 0.5
    x += 1
  proba += p/N

Submission status: Runtime Error

Solution code:
import math

s = input().split()
n = s[0]
k = s[1]

proba = 0

for i in range(1, k):
  n_coin = int(math.log(k/i,2)) + 1
  print(i, n_coin)
  proba += float(1)/n*((0.5)**n_coin)

if n >= k:
	proba += float(n-k+1)/n
print(proba)

Submission status: Runtime Error

Solution code:
import math

s = input().split()
n = s[0]
k = s[1]

proba = 0

for i in range(1, k):
  n_coin = int(math.log(k/i,2)) + 1
  print(i, n_coin)
  proba += float(1)/n*((0.5)**n_coin)

if n >= k:
	proba += float(n-k+1)/n

Submission status: Runtime Error

Solution code:
import math

inp = input().split()
n = inp[0]
k = inp[1]
proba = 0

for i in range(1, k):
  n_coin = int(math.log(k/i,2)) + 1
  print(i, n_coin)
  proba += float(1)/n*((0.5)**n_coin)

if n >= k:
	proba += float(n-k+1)/n

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
s = b
p = 0.0
for i in range(1,a+1):
	tmp = 1.0/a
	now = i
	while now < b:
		now = now*2
        tmp = tmp/2
	p = p+tmp
print(%.12f%p)

Submission status: Runtime Error

Solution code:
N,k=map(int,input().split())
ans=0
for i in range(1,N+1):
  cnt=0
  while i < k:
    frag*(1/2)
    cnt+=1
    i*=2
  ans += (1/N)*i*((1/2)**cnt)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = [int(a) for a in input().split()]

prob = 0

for i in range(1, N+1):
    j = i
    inverse_p = j
    while j < K:
        j *= 2
        inverse_p *= 2
    prob += 1/ p

print(prob)

Submission status: Runtime Error

Solution code:
N,k=map(int,input().split())
ans=0
for i in range(1,N+1):
  cnt=0
  while i < k:
    frag*(1/2)
    cnt+=1
    i*=2
  ans += (1/N)*i*(1/2)**cnt
print(ans)