Smallest Int Divisible by K | C++ | 100% fast
first we rule out 2 obvious cases where K will never divide into n, where n is a number consisting of only 1s.\n\n1. When K is divisible by 2, because for any n
first we rule out 2 obvious cases where K will never divide into n, where n is a number consisting of only 1s.\n\n1. When K is divisible by 2, because for any number (a) to be divisible by another number (b), it logically follows that a must be also divisible by divisors of b. And any n will never be divisible by 2.\n2. When K is divisible by 5, reason same as 2.\n\nWith these eliminated we have removed a huge number of potential Ks,  leaving only those that end with 1, 3, 7, or 9.\n\nNow we perform division just like how you would on paper, by dividing the remainder. This way the program never has integer overflow. \ne.g. to divide 13 into 111111 we:\n\tfirst digit: divide 1 by 13= 0, remainder 1.\n\tsecond digit: multiply remainder of 1 by 10, plus 1=11, divide by 13 = 0, remainder of 11.\n\tthird digit: multiply remainder of 11 by 10, plus 1=111, divide by 13= 8, remainder of 7,\n\tfourth digit: multiply remainder of 7 by 10, plus 1=71, divide by 13=  5, remainder of 6,\n\tfifth digit: multiply remainder of 6 by 10, plus 1=61, divide by 13=4, remainder of 9,\n\tsixth digit: multiply remainder of 9 by 10, plus 1=91, divide by 13=7, remainder of 0.\n\nAnd you can see that the pattern is clear, the remainder rolls upwards until the remainder is the divisor itself, or it rolls over the size of the divisor, which restarts the pattern from the beginning. Logically this makes sense, as whenever the remainder is larger than the divisor that means you can divide into the number 1 more time.\n\nHere this property can be used to set the limit that when reached, means it is clear that K will never divide into n.\n```\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int K) {\n        if (K%2==0||K%5==0)\n            return -1;\n\n        int temp=0;\n        for(int i=1;i<=K;i++)\n        {\n            temp=(temp*10)%K+1;\n            if(temp%K==0)\n            {\n                return i;\n            }\n        }\n        return -1;\n\n    }\n};\n```
['C']