Count of numbers with all digits same in a given range | Python3 program to count the total numbers in the range L and R which have all the digit same ; Function that count the total numbersProgram between L and R which have all the digit same ; length of R ; tmp has all digits as 1 ; For each multiple of tmp in range 1 to 9 , check if it present in range [ L , R ] ; Increment the required count ; Driver Code
import math NEW_LINE def count_same_digit ( L , R ) : NEW_LINE INDENT tmp = 0 ; ans = 0 ; NEW_LINE n = int ( math . log10 ( R ) + 1 ) ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT tmp = tmp * 10 + 1 ; NEW_LINE for j in range ( 1 , 9 ) : NEW_LINE INDENT if ( L <= ( tmp * j ) and ( tmp * j ) <= R ) : NEW_LINE INDENT ans += 1 ; NEW_LINE DEDENT DEDENT DEDENT return ans ; NEW_LINE DEDENT L = 12 ; R = 68 ; NEW_LINE print ( count_same_digit ( L , R ) ) NEW_LINE