fork download
  1. def solve(L, R):
  2. count = 0
  3.  
  4. # For each digit (1 through 9) construct numbers where the first and last digits are the same
  5. for first_last_digit in range(1, 10):
  6. # Single-digit numbers
  7. if L <= first_last_digit <= R:
  8. count += 1
  9.  
  10. # Multi-digit numbers where first and last digits are the same
  11. multiplier = 10 # Start with 10 and go higher (like 11, 101, 1001, ...)
  12. while True:
  13. num = first_last_digit * multiplier + first_last_digit
  14. if num > R:
  15. break
  16. if num >= L:
  17. count += 1
  18. multiplier *= 10 # Move to the next higher number structure
  19.  
  20. return count
  21.  
  22. # Input
  23. L = 47#int(input())
  24. R = 74#int(input())
  25.  
  26. # Get the output
  27. out_ = solve(L, R)
  28. print(out_)
  29.  
Success #stdin #stdout 0.03s 25600KB
stdin
Standard input is empty
stdout
def solve(L, R):
    count = 0
    
    # For each digit (1 through 9) construct numbers where the first and last digits are the same
    for first_last_digit in range(1, 10):
        # Single-digit numbers
        if L <= first_last_digit <= R:
            count += 1
        
        # Multi-digit numbers where first and last digits are the same
        multiplier = 10  # Start with 10 and go higher (like 11, 101, 1001, ...)
        while True:
            num = first_last_digit * multiplier + first_last_digit
            if num > R:
                break
            if num >= L:
                count += 1
            multiplier *= 10  # Move to the next higher number structure

    return count

# Input
L = 47#int(input())
R = 74#int(input())

# Get the output
out_ = solve(L, R)
print(out_)