-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfDividingNumbers728.java
More file actions
46 lines (40 loc) · 1.13 KB
/
SelfDividingNumbers728.java
File metadata and controls
46 lines (40 loc) · 1.13 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.*;
public class SelfDividingNumbers728 {
public static void main(String[] args) {
int left = Integer.parseInt(args[0]);
int right = Integer.parseInt(args[1]);
List<Integer> res = selfDividingNumbers(left, right);
System.out.println(res);
}
public static List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> ret = new ArrayList<>();
Map<Character,Integer> map = null;
for(int value = left; value <= right; value++) {
System.out.println("\n\nvalue: " + value);
if(value < 10) {
ret.add(value);
continue;
}
int work = value;
if(("" + work).indexOf("0") >= 0) {
continue;
}
int resid;
int divi;
do {
resid = work % 10;
divi = work / 10;
System.out.println("divi: " + divi + " , resid: " + resid + " , value/resid = " + value + "%" + resid + " = " + (value%resid));
if(value % resid != 0) {
work = -1;
break;
}
work = divi;
} while(work >0);
if(work >= 0) {
ret.add(value);
}
}
return ret;
}
}