Length of the smallest number which is divisible by K and formed by using 1 's only | Function to return length of the resultant number ; If K is a multiple of 2 or 5 ; Generate all possible numbers 1 , 11 , 111 , 111 , ... , K 1 's ; If number is divisible by k then return the length ; Driver code
def numLen ( K ) : NEW_LINE INDENT if ( K % 2 == 0 or K % 5 == 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT number = 0 ; NEW_LINE len = 1 ; NEW_LINE for len in range ( 1 , K + 1 ) : NEW_LINE INDENT number = number * 10 + 1 ; NEW_LINE if ( ( number % K == 0 ) ) : NEW_LINE INDENT return len ; NEW_LINE DEDENT DEDENT return - 1 ; NEW_LINE DEDENT K = 7 ; NEW_LINE print ( numLen ( K ) ) ; NEW_LINE