【Java】An easy Solution By using the knowledge points that primary school students understand
Cycle to find the right X:\n\njava\n//Here is the idea of problem solving\n\nint x = 1\n\nint ans = 1;\n\nwhile (x % K != 0) {\n\tx = x * 10 + 1;\n\t++ans;\n}\n
Cycle to find the right X:\n\n```java\n//Here is the idea of problem solving\n\nint x = 1\n\nint ans = 1;\n\nwhile (x % K != 0) {\n\tx = x * 10 + 1;\n\t++ans;\n}\n```\n\nIt will overflow here, so it is changed to X % = k; x = x * 10 + 1;\n\nPossibility of dead circulation\n\nIt\'s actually a multiple of 2 and 5. At this time, 10 can be divided and needs to be excluded\n\nSolution \n```java\nclass Solution {\n    public int smallestRepunitDivByK(int K) {\n        if (K % 2 == 0 || K % 5 == 0)\n            return -1;\n        int i = 1;\n        for (int n = 1; n % K != 0; i++) {\n            n %= K;\n            n = n * 10 + 1;\n        }\n        return i;\n    }\n}\n```
['Java']