Smallest Integer Divisible by K
Given a positive integer K, we must find the length of the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. If there 
Given a positive integer `K`, we must find the *length* of the smallest positive integer `N` such that `N` is divisible by `K`, and `N` only contains the digit `1`. If there is no such `N`, return `-1`. Therefore the following constraints must be met.\n\n* `N % K == 0`\n* length of `N` is minimized\n* `N` only contains the digit `1`\n\nThe first important item to note is that `N` may not fit into a 64-bit signed integer. This means that we can not simply iterate though the possible values of `N` and mod `K`. \n\nTo find a way to reduce the problem, lets take the example of `K=3`. The value `3` has the following possible remainders when dividing.\n\n| 0 | 1 | 2 |\n|:-:|:-:|:-:|\n\nNow, lets find the value of `N` by brute-force. In the table below, we can see that the condition `N % K == 0` is first met with the value of `111`. More interestingly, we can see that the pattern `1 -> 2 -> 0` repeats. \n\n|  N  | 1 | 11 | 111 | 1111 | 11111 | 111111\n|:---:|:-:|:--:|:---:|:----:|:-----:|:-----:|\n| N%K | 1 |  2 |  0  |   1  |   2   |   0   |\n\nNow, lets take a look at the example `K=6`. We can see that there are a finite number of possible remainders for any value mod `K` and that we only need to iterate thought the sequence of remainders *once* to find that `N` is not divisible by `K`.\n\n| 0 | 1 | 2 | 3 | 4 | 5 |\n|:-:|:-:|:-:|:-:|:-:|:-:|\n\n|  N  | 1 | 11 | 111 | 1111 | 11111 | 111111 | 1111111 |\n|:---:|:-:|:--:|:---:|:----:|:-----:|:------:|:-------:|\n| N%K | 1 |  5 |  3  |   1  |   5   |    3   |    1    |\n\nThe final piece that we must solve is how to calculate the `N%K` sequence: how to find the next remainder. We can\'t go though the values of `N` because it might not fit in a 64-bit integer. Let take a look at how we would calculate the next value of `N` and go from there. \n\n\n`N next = (N * 10) + 1` : the next value of `N` `1 -> 11 -> 111 ...`\n`remainder = N%K` : the remainder\n\n`(N next)%K  = ((N * 10) + 1)%K` : we can mod both sides of our next remainder equation \n`(N next)%K  = ((N * 10)%K + 1%K)%K` : the equation can then be rearranged. "It is useful to know that modulos can be taken anywhere in the calculation if it involves only addition and multiplication." *[- duke-cps102](http://db.cs.duke.edu/courses/cps102/spring10/Lectures/L-04.pdf)*\n`(N next)%K  = ((N * 10)%K + 1)%K` : `1` mod anything is `1`\n`(N next)%K  = ((N * 10)%K + 1)%K` : `1` mod anything is `1`\n**`remainder next = (remainder*10 + 1) %K`** : knowing that `N%K` is our remainder, we have now have a general equation that can find our next remainder value without knowing the value of `N`.\n\n```\ndef smallestRepunitDivByK(self, K: int) -> int:\n    r = 0\n    for c in range(1, K+1):\n        r = (r*10 + 1)%K\n        if r == 0: return c\n    return -1\n```\n\nThe runtime of this solution is **`O(K)`**. \nThe space complexity is **`O(1)`**.
['Python3']