Repeated Unit Divisibility | To find least value of k ; To check n is coprime or not ; to store R ( k ) mod n and 10 ^ k mod n value ; Driver code
def repUnitValue ( n ) : NEW_LINE INDENT if ( n % 2 == 0 or n % 5 == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT rem = 1 NEW_LINE power = 1 NEW_LINE k = 1 NEW_LINE while ( rem % n != 0 ) : NEW_LINE INDENT k += 1 NEW_LINE power = power * 10 % n NEW_LINE rem = ( rem + power ) % n NEW_LINE DEDENT return k NEW_LINE DEDENT n = 13 NEW_LINE print ( repUnitValue ( n ) ) NEW_LINE