Timus 1014. The product of digits

Source: Internet
Author: User
Document directory
  • Input
  • Output
  • Sample
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
Input Output
10 25

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.