java solution with explanation
\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if(k%2==0 || k%5==0)\n            return -1;\n        int rem=0;//to calculate previo
```\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if(k%2==0 || k%5==0)\n            return -1;\n        int rem=0;//to calculate previous rem\n        for(int i=1;i<=k;i++)\n        {\n            rem=(rem*10+1)%k;\n            if(rem==0)\n                return i;\n        }\n        \n        return -1;\n    }\n}\n```\n\n![image](https://assets.leetcode.com/users/images/b4f16f94-f023-4bfc-8731-5e0588440716_1640838030.6588607.png)\n
['Java']