Java solution with simple intuition
\nclass Solution {\n    public int smallestRepunitDivByK(int K) {\n        // Obviously if last digit is 1, then K can never be a factor of 2 or 5\n        if (
```\nclass Solution {\n    public int smallestRepunitDivByK(int K) {\n        // Obviously if last digit is 1, then K can never be a factor of 2 or 5\n        if ((K % 2 == 0) || (K % 5 == 0)) {\n            return -1;\n        } \n        // Remainder that will be added to next 1\n        int rem = 0;\n        // keep track of length of 1\n        int count = 1;\n        int value = 1;\n        // Make sure that first number to try divisible should be greater than K\n        while (value < K) {\n            value = Integer.parseInt(value + "1");\n            ++count;\n        }\n        // As we know remaining nubers are only odd and not factor of 2 or 5 then definitely all other numbers are valid.\n        while (value % K != 0) {\n            rem = value % K;\n            value = Integer.parseInt(rem + "1");\n            ++count;\n        }\n        return count;\n    }\n}\n```
[]