coolness of the number is defined as the number of "101"s occuring in its binary representation. If the number binary representation has "101" then it’s coolness is 1
A number is defined as very cool if it’s coolness is greater than or equal to k
input : 21 2 output: 1
but i’m getting
output:2 instead of 1
def v(j):
res=''
c=0
while j>0:
res=res+str(j%2)
j=j//2
for i in range(2,len(res)):
if res[i]+res[i-1]+res[i-2]=="101":
c+=1
return c>=k
n,k=map(int,input().split())
r=0
for i in range(2,n+1):
if v(i):
r=r+1
print(r)
>Solution :
while j>0:
res=res+str(j%2)
j=j//2
for i in range(2,len(res)):
if res[i]+res[i-1]+res[i-2]=="101":
c+=1
return c>=k