I need to find all numbers in a certain range that end with specific digits.
For example:
find all numbers up-to
15that end with5. Result should be2because5and15end with5.find all numbers up-to
125that end with12. Result should be also2because12and112end with12.
I tried this brute-force code:
def findnumber(n, m):
count = 0
for i in range(1, m+1):
if i%10**len(str(n)) == n:
count += 1
return count
print(findnumber(5,15))
But I need to make the code more efficient.
- The legal values are:
1 <= n, m <= 10**9