Skip to content

Commit 06ed8d8

Browse files
committed
cpp
1 parent cc5ef88 commit 06ed8d8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

1015.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution {
2+
public:
3+
int smallestRepunitDivByK(int K) {
4+
5+
if(K%2==0){
6+
return -1;
7+
}
8+
if(K%5==0){
9+
return -1;
10+
}
11+
if(K==1){
12+
return 1;
13+
}
14+
15+
int n=1;
16+
int remainder=1;
17+
18+
int count=1;
19+
20+
while(remainder!=0){
21+
22+
remainder=remainder*10 + 1 ;
23+
remainder=remainder%K;
24+
count++;
25+
26+
if(remainder==0){
27+
return count;
28+
}
29+
30+
}
31+
32+
return -1;
33+
34+
35+
36+
}
37+
};

0 commit comments

Comments
 (0)