Python不含 101 的数

360影视 2025-01-16 01:55 2

摘要:defcount_no_101(l, r):count = 0for num in range(l, r + 1):binary = bin(num)[2:] # 将数字转换为二进制字符串if '101' not in binary:count += 1ret

defcount_no_101(l, r):count = 0for num in range(l, r + 1):binary = bin(num)[2:] # 将数字转换为二进制字符串if '101' not in binary:count += 1return count# 输入l, r = map(int, input.split)# 计算并输出结果result = count_no_101(l, r)print(result)

来源:若若课堂

相关推荐