forked from sherxon/AlgoDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductofDigits1014.java
More file actions
43 lines (38 loc) · 1.01 KB
/
ProductofDigits1014.java
File metadata and controls
43 lines (38 loc) · 1.01 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
package timus;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Created by sherxon on 12/3/16.
*/
public class ProductofDigits1014 {
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int n=in.nextInt();
if(n==0) System.out.println(10);
else{
List<Integer> set= new ArrayList<>();
getDivisors(n, set);
if(set.isEmpty()) System.out.println(-1);
else set.stream().sorted().forEach(System.out::print);
}
}
private static void getDivisors(int n, List<Integer> set) {
if(n<10){
set.add(n);
}else{
boolean t=false;
for (int i = 9; i >1 ; i--) {
if(n%i==0) {
t=true;
set.add(i);
getDivisors(n/i, set);
break;
}
}
if(!t){
set.clear();
}
}
}
}