1015. Smallest Integer Divisible by K

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public int smallestRepunitDivByK(int k) {
if (k % 2 == 0 || k % 5 == 0) {
return -1;
}

int temp = 1;
int count = 1;

while (temp % k != 0) {
temp = temp % k;
temp = temp * 10 + 1;
count++;
}

return count;
}
}

References

1015. Smallest Integer Divisible by K