-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem032.java
More file actions
31 lines (31 loc) · 987 Bytes
/
Problem032.java
File metadata and controls
31 lines (31 loc) · 987 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
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
public class Problem032 {
private static boolean isPan(String s) {
if (s.length() != 9) {
return false;
}
String[] sArray = s.split("");
String[] pan = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
Arrays.sort(sArray);
return Arrays.equals(pan, sArray);
}
public static void main(String[] args) {
int sum = 0;
HashSet<Integer> prods = new HashSet<Integer>();
for (int i = 1; i < 9999; i++) {
for (int j = 1; j * i < 9876543 && j < 9999; j++) {
if (isPan(String.valueOf(i) + String.valueOf(j)
+ String.valueOf(i * j))) {
prods.add(j * i);
}
}
}
Iterator<Integer> itr = prods.iterator();
while (itr.hasNext()) {
sum += itr.next();
}
System.out.println(sum);
}
}