Solution
C++ []\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int k) {\n        for (int r=0,N=1;N<=k;N++) {\n            if ((r=(r*10+1)%k)==0) {\n         
```C++ []\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int k) {\n        for (int r=0,N=1;N<=k;N++) {\n            if ((r=(r*10+1)%k)==0) {\n                return N;\n            }\n        }\n        return -1;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def smallestRepunitDivByK(self, k: int) -> int:\n        if k%2==0 or k%5==0:\n            return -1\n        else:\n            cur = 1\n            res = 1\n            while cur%k!=0:\n                cur = (10*cur+1)%k\n                res += 1\n            return res\n```\n\n```Java []\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n        \n        int phi = get_euler(k * 9);\n        int res = phi;\n        for (int i = 1; i <= phi / i; i++) {\n            if (phi % i == 0) {\n                if (qmi(10, i, 9 * k) == 1) return i;\n                if (qmi(10, phi / i, 9 * k) == 1) res = Math.min(res, phi / i);\n            }\n        }\n        return res;\n    }\n    private int get_euler(int x) {\n        int res = x;\n        for (int i = 2; i <= x / i; i++) {\n            if (x % i == 0) {\n                res = res / i * (i - 1);\n                while (x % i == 0) x /= i;\n            }\n        }\n        if (x > 1) res = res / x * (x - 1);\n        return res;\n    }\n    private long qmi(long a, long k, long p) {\n        long res = 1;\n        while (k > 0) {\n            if ((k & 1) == 1) res = res * a % p;\n            a = a * a % p;\n            k >>= 1;\n        }\n        return res;\n    }\n}\n```
['C++', 'Java', 'Python3']