# range循环打印 1~n ,n转化成字符串,存入列表中? 检测到有x就加一
# n,x = map(int,input().split())
# result = 0
# for i in range(1,n+1):
# i = str(i)
# for j in i:
# if j == str(x):
# result += 1
# else:
# continue
# print(result)
# 以上未在时间限制内给出答案,pass
# 采用数位法:
n,x = map(int,input().split())
result = 0
for i in range(1,n+1):
while i:
if i % 10 == x:
result += 1
i = i // 10
print(result)
有意思的是 n % 10 永远得到n最右边的数,n // 10 可以消除n最右边的数,两个结合,可以直接遍历到任何整数n 的所有位

京公网安备 11010502036488号