Python modulo approach with mathematical proof
Key observation: \n\t if k is divisible by 2 or 5, there is no way 11....1 can be divisible by k, because anything that can be divided by 2 must be even at last
Key observation: \n\t* if k is divisible by 2 or 5, there is no way 11....1 can be divisible by k, because anything that can be divided by 2 must be even at last digit, and by 5 must end with either 0 or 5;\n\t* otherwise, k can divide 11...1.  There is no need to check for repeated modulo to detect cycle because there will be no cycle. The proof below was quoted from @DBabichev with his post: https://leetcode.com/problems/smallest-integer-divisible-by-k/discuss/948435/Python-Math-Pigeon-holes-explained\n\t* to avoid overflow when 11.111 is too big, another observation is that the next sequence of 1s are basically (previousNumber*10+1)%k = ((previousQuotient*k+previousMod)*10+1)%k == (previousMod*10+1)%k\n```\nclass Solution:\n    def smallestRepunitDivByK(self, k: int) -> int:\n        #R1D12I8C0X9=T30  : modulo\n        m,l=1%k,1\n        seen=set()\n        while True:\n            if m==0:\n                return l\n            elif (m*10+1)%k in seen:\n                return -1\n            m,l=(m*10+1)%k,l+1\n            seen.add(m)\n            \n    def smallestRepunitDivByK(self, k: int) -> int:\n        m,seen=0,set()\n        for i in range(k):\n            m=(m*10+1)%k\n            if m in seen:\n                return -1\n            if m==0:\n                return i+1\n            seen.add(m)\n            \n    def smallestRepunitDivByK(self, k: int) -> int: # no need to check dup, if there is a repeated modulo, there exists a 111...111 that is divisible by k\n        \'\'\'\n        Proof using Pigeon hole theorem, copied from @DBabichev with his post: https://leetcode.com/problems/smallest-integer-divisible-by-k/discuss/948435/Python-Math-Pigeon-holes-explained\n        First of all, let us notice, that if number is divisible by 2 or by 5, then we need to return -1 immediatly, because number ending with 1 can not divide by 2 or 5. From now on we assume, that K is not divisible by 2 or 5. Let us consider numbers:\n\n1\n11\n111\n...\n111...111,\n\nwhere were have K ones in the last group. Then, there can be only two cases:\n\nAll reminders of given numbers when we divide by K are different.\nSome two reminders are equal.\nIn the first case, we have K numbers and also K possible reminders and they are all different, it means, that one of them will be equal to 0.\n\nIn the second case, two numbers have the same reminder, let us say number 11...1111 with a ones and 111...11111 with b ones, where b > a. Then, difference of these two numbers will be divisible by K. What is the difference? It is number 11...1100...000 with b-a ones and a zeroes at the end. We already mentioned that K is not divisible by 2 or 5 and it follows, that 11...111 divisible by K now, where we have b-a ones.\n\nSo, we proved the following statements: if K not divisible by 2 and 5, then N <= K where N is the number of how many 1s. What we need to do now is just iterate through numbers and stop when we find number divisible by K. To simplify our cumputation, we notice, that each next number is previous multiplied by 10 plus 1.\n        \'\'\'\n        if k%2==0 or k%5==0:\n            return -1\n        m=0\n        for i in range(k):\n            m=(m*10+1)%k\n            if m==0:\n                return i+1\n```
[]