Python Simple Solution O(k) Time, O(1) Space w/ Explanation
When you run through the multiples of the prime numbers from 1 to 9, you\'ll notice that 2 and 5 don\'t have any muliples that end in 1. The reason for this is 
When you run through the multiples of the prime numbers from 1 to 9, you\'ll notice that 2 and 5 don\'t have any muliples that end in 1. The reason for this is that a number that is of the form 111...111 = 10^n + 10^(n-1) + ... + 1. The modulus of a sum is the sum of moduluses and since 2 divides 10 and 5 divides 10, 111...111 mod 10 = 1. Hence, we can immediately rule out all numbers that have 2 and 5 in their prime factorization.\n\nThe rest is simply using the modular property that the modulus of a sum or product is the same as the sum/product of the moduluses.\nFor instance, let\'s use 7 as an example:\n1 mod 7 = 1. Ok so 7 needs more 1\'s. To add a 1, we multiply by 10 and add 1 => 1 * 10 + 1 = 11. Then, we can check if 11 mod 7 is 0. No it isn\'t so we need to add another 1. However, since we\'re only dealing with moduluses, we can use the property descriped above and only store the remainder: 1 * 10 + 1 = 1 mod 7 * 10 mod 7 + 1 mod 7 = 4. So now, our currect remainder is 4. When we multiply by 10 and add 1 again to append the next digit, aka 1 * 100 + 1 * 10 + 1, we can use our previous remainder. This is because 1 * 100 + 1 * 10 + 1 = 10 * (1 * 10 + 1) + 1. Taking the modulus of that, 10 mod 7 * (previous remainder) + 1 mod 7 = (3 * 4 + 1) mod 7 = 6. Essentially, all we\'re doing is using the previous remainder to compute the next one.\n\n```\nclass Solution:\n    def smallestRepunitDivByK(self, k: int) -> int:\n        if k % 2 == 0 or k % 5 == 0: return -1\n        \n        digits, rem = 1, 1\n        while rem % k != 0:\n            rem = (rem % k) * (10 % k) + 1\n            digits += 1\n            \n        return digits
['Math', 'Python']