1class Solution {2public int smallestRepunitDivByK(int k) {3// if (k % 2 == 0 || k % 5 == 0) return -1; // this trick may save a little time4boolean[] hit = new boolean[k];5int n = 0, ans = 0;6while (true) { // at most k times, because 0 <= remainder < k7++ans;8n =9(n * 10 + 1)10% k; // we only focus on whether to divide, so we only need to keep the remainder.11if (n == 0) return ans; // can be divisible12if (hit[n])13return -1; // the remainder of the division repeats, so it starts to loop that means it14// cannot be divisible.15hit[n] = true;16}17}18}