[C++] O(1) Space , Deriving Formula
Code is reffered from lee215\nIt is pretty much clear that we don\'t have to look further if k is divisible by 2 or 5 since 1, 11, 111 can not be divided by 2 o
Code is reffered from [lee215](https://leetcode.com/lee215/)\nIt is pretty much clear that we don\'t have to look further if k is divisible by 2 or 5 since 1, 11, 111 can not be divided by 2 or 5, otherwise there exist a solution\n```\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int k) {\n        if(k%2==0|| k%5==0) return -1;\n        \n        for(int N=1,r=0;N<=k;N++){ \n            // let\'s 1111 = a+b\n            // 1111 = 1110 + 1\n            // 1111%k = (1110%k + 1%k)%k\n            // 1111%k = (1110%k + 1)%k\n            // 1111%k = (111%k*10 +1)%k\n            // now 111%k is the rem of last 111\n\t\t\t// 1111%k  = (r*10 + 1)%k\n            // here r is the previous remainder\n            r = (r*10+1)%k;\n            if(r==0) return N;\n        }\n        return 0;\n    }\n};\n\n```
[]