#输入
a=input()
b = int(a)
#转化成二进制
c =bin(b)
num = 0#这个是统计有几个101的个数的
str_m =[]#这个是存二进制每一个位的整数的,后来发现这步可以省,没改
str_c =list(str(c).replace('0b',''))#字符串分割成数组
location = 0#定位第一个101所在的位置
num_location = 0#输出定位所在的整型位置
n = len(str_c)-1#这是为了计算二进制字符数组的长度的
#计算有多少个101
for i in range(0,len(str_c)-2):
if (str_c[i]=='1')&(str_c[i+1]=='0')&(str_c[i+2]=='1'):
num = num+1
#计算101出现的第一个位置,这里比较绕,所在的位置为1所在的起点
for i in range(0,len(str_c)-2):
if(str_c[n-i]=='1')&(str_c[n-i-1]=='0')&(str_c[n-i-2]=='1'):
location = i
break
#把数组数据头尾转换,然后存到一个新数组
for i in range(0,n+1):
str_m.append(int(str_c[n-i]))
#将101所在的位置二进制转换成十进制,比如11011,101第一个出现的位置就是3
for i in range(0,location+1):
if str_m[i]==1:
num_location = 2**i +num_location
#如果存在101就输出,不存在就输出0,-1,(输出格式是m,n,m-101个数,n-起始位置)
if num==0:
print(0,-1)
else:
print(num,num_location,location,str_c)
进行了调试: