Python with modular arithmetic
If x mod k = a, when x * y + c mod k = (a * y + c) mod k\nSo we can do the while loop as follow\nhttps://en.wikipedia.org/wiki/Modular_arithmetic\n\nclass Solut
If x mod k = a, when x * y + c mod k = (a * y + c) mod k\nSo we can do the while loop as follow\nhttps://en.wikipedia.org/wiki/Modular_arithmetic\n```\nclass Solution(object):\n    def smallestRepunitDivByK(self, K):\n        seen = set()\n        curr_mod = 1 % K\n        length = 1\n        while(curr_mod not in seen):\n            seen.add(curr_mod)\n            if curr_mod == 0:\n                return length\n            # update if it does not satisfy\n            curr_mod = (curr_mod * 10 + 1) % K\n            length += 1\n        return -1\n```\n\nHowever, with the python infinite numbering system, you can also do brute force with higher complexity\n```\nclass Solution(object):\n    def smallestRepunitDivByK(self, K):\n        seen = set()\n        curr = 1 \n        length = 1\n        while((curr % K) not in seen):\n            seen.add(curr % K)\n            if curr % K == 0:\n                return length\n            # update if it does not satisfy\n            curr = curr * 10 + 1\n            length += 1\n        return -1\n```
[]