def solve(n, k):
q, x, ans = n, 1, 0
while q > 0:
digit = q % 10
q //= 10
ans += q * x
if digit == k:
ans += n % x + 1
elif digit > k:
ans += x
x *= 10
return ans
r = solve(213, 1)
print(r)
To embed this project on your website, copy the following code and paste it into your website's HTML: