-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path1015.java
More file actions
31 lines (31 loc) · 943 Bytes
/
1015.java
File metadata and controls
31 lines (31 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public int smallestRepunitDivByK(int K) {
if (K % 2 == 0 || K % 5 == 0) {
return -1;
}
int n = 1;
int count = 1;
while (n % K != 0) {
n = n * 10 + 1;
n = n % K;
count++;
}
return count;
}
}
__________________________________________________________________________________________________
sample 31556 kb submission
class Solution {
public int smallestRepunitDivByK(int K) {
//if (K % 2 == 0 || K % 5 == 0) return -1;
int r = 0;
for (int N = 1; N <= K; ++N) {
r = (r * 10 + 1) % K;
if (r == 0) return N;
}
return -1;
}
}
__________________________________________________________________________________________________