✅100% faster C++ Code O(1) space ✅
\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n \n    int smallestRepunitDivByK(int k) {\n       
\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n \n    int smallestRepunitDivByK(int k) {\n        int m=k;\n        if(k%2==0 || k%5==0)return -1;\n        int digits=0,c=0;\n         m=k;\n        while(m!=0)m=m/10,digits=digits*10+1,c++;\n        \n        int rem=(digits%k);\n        while(rem!=0){\n            c++;\n            rem=rem*10+1;\n            rem=rem%k;\n        }\n        return c;\n    }\n};\n```
['C++']