[Kotlin] Simple solution, explained
The key to understanding the solution (and hint given), is to understand why using the remainder R to get to the next number to test can be used in place of N, 
The key to understanding the solution (and hint given), is to understand why using the remainder R to get to the next number to test can be used in place of N, where N is 1, 11, 111, and so on.  So instead of using N * 10 + 1, we can use R * 10 + 1.\n\nAssume that taking modulo K of N gives remainder R.  N then equals K * x + R (x is N / K integer value, we don\'t really care what its value is).  \nThe next number to test is ((K * x + R) * 10 + 1).  \nUsing the distributive property for multiplication, this is equivalent to ((K * x * 10)  + (R * 10) + 1).\nTaking modulo K of the next number is ((K * x * 10)  + (R * 10) + 1) % K\nUsing the distributive property for modulo, this is equivalen to ( (K * x * 10) % K + (R * 10) % K + 1 % K) % K\n(The last %K is appended in case the separate remainders added together exceed K)\nSince (K * x * 10) % K is always 0, (clearly evenly divisible by K), this can be reduced to:\n( (R * 10) % K + 1 % K) % K\nUsing the distributive property again, this time to combine items, we have (R * 10 + 1) % K\n\nThis is why, in the end, we can use (R * 10 + 1) % K for each iteration.  Since the remainder is always less than K, we will never overflow like we would if we keep multiplying by 10 and adding 1.\n\nFinally, any number divisible by 2 (even), or 5 (which ends in 5 or 0), can never be evenly divided into a number that is all ones, so those can be easily eliminated at the start.  It turns all other numbers have a solution, so no check is required to avoid an endless loop.\n\n```\n fun smallestRepunitDivByK(K: Int): Int {\n     if (K % 2 == 0 || K % 5 == 0) {\n         return -1\n     }\n     var n = 1\n     var len = 1\n     while(n % K != 0) {\n         n = (n * 10 + 1) % K\n         len++\n     }\n     return len\n }\n
['Math', 'Kotlin']