Document directory
Timus 1014. The product of digits requires a minimum integer. The product of each digit is equal to the specified number.
1014. The product of digitstime limit: 1.0 second
Memory limit: 16 mbyour task is to find the minimal positive integer number
QSo that the product of digits
QIs exactly equal
N. Inputthe input contains the single integer number
N(0 ≤
N≤ 109). outputyour program shocould print to the output the only number
Q. If such a number does not exist print −1. Sample
Problem Source:Ural State University internal contest'99 #2
The answer is as follows: 1 using system;
2 using system. IO;
3
4 namespace skyiv. Ben. timus
5 {
6 // http://acm.timus.ru/problem.aspx? Space = 1 & num = 1014
7 class t1014
8 {
9 static void main ()
10 {
11 new t1014 (). Run (console. In, console. Out );
12}
13
14 void run (textreader reader, textwriter writer)
15 {
16 out (writer, getdigits (Int. parse (reader. Readline ())));
17}
18
19 int [] getdigits (int n)
20 {
21 int [] digits = new int [11];
22 if (n = 0) digits [10] = 1;
23 else if (n = 1) digits [1] = 1;
24 else
25 {
26 For (INT I = 9; I> 1; I --)
27 {
28 while (n> 1 & N % I = 0)
29 {
30 N/= I;
31 digits [I] ++;
32}
33}
34 if (n! = 1) digits = NULL;
35}
36 return digits;
37}
38
39 void out (textwriter writer, int [] digits)
40 {
41 if (digits = NULL) writer. writeline (-1 );
42 else
43 {
44 For (INT I = 0; I <digits. length; I ++)
45 {
46 int n = digits [I];
47 While (n --> 0) writer. Write (I );
48}
49 writer. writeline ();
50}
51}
52}
53}
54
The solution to this question is direct. However, when the input N is 0, the output answer should be 10 instead of-1.
Returned directory