Python
The Pigeonhole Principle from the other solutions also apply here: If we don\'t have the remainder 0 after k iterations (k iterations counted inside the last wh
The Pigeonhole Principle from the other solutions also apply here: If we don\'t have the remainder `0` after `k` iterations (`k` iterations counted inside the last while-loop) we have `k` spaces for `k-1` candidates and we will get a duplicate.\n\n```python\nclass Solution:\n    def smallestRepunitDivByK(self, k):\n        #start from n\n        n = 1\n        while n<k: \n            n = 10*n + 1\n        #set of remainders\n        rm = set()\n        while True:\n            if n%k==0:\n                return len(str(n))\n            if n%k in rm:\n                return -1\n            rm.add(n%k)\n            n = 10*n + 1\n```
[]