-
Notifications
You must be signed in to change notification settings - Fork 5
/
Minimum_Number.java
59 lines (55 loc) · 1.42 KB
/
Minimum_Number.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Write a program to find the minimum value of B for a given value of A. If we multiply the digits of B we get the exact
value of A.
Result B must be contains more than 1 digit.
* Input : 10
* Output : 25
* Explanation : 2*5 = 10 and this is minimum value of B
* Input : 100
* Output : 455
* Explanation : 4*5*5 = 100
*/
import java.util.*;
public class Minimum_Number
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = findMinB(A);
if(B>0)
{
System.out.println(B);
}
else
{
System.out.println("No value found");
}
}
public static int findMinB(int A)
{
int B = 10;
while (true) {
String b = Integer.toString(B);
int product = 1;
for (int i = 0; i < b.length(); i++)
{
int c = Integer.parseInt(String.valueOf(b.charAt(i)));
if (c!=0 && A % c == 0)
{
product = product * c;
}
else
{
break;
}
}
if (product == A)
{
return B;
} else if (product > A) {
return 0;
}
B++;
}
}
}