A written examination question

Source: Internet
Author: User

Description: Write a function, input a positive integer N, and return a minimum positive integer m (M contains at least two digits), so that the product of M is equal to n. If n does not exist, -1,

For example:

Input: 12

Output: 26

Input: 100

Output: 455

Input: 7

Return Value: 17


# Include <iostream> using namespace STD; int func (int n) {int num = 0; int s; int M [10] = {0}; int p = 0; // subscript of array M int sum = N; int I = 2; // 1 ~ 81 double digits are used to indicate int q = 9; bool falg = false; while (sum> 9 * q) // number of digits greater than 81 must be expressed as 82 ~ Between 729 with a 3-digit representation of {I ++; Q * = 9;} int r = I-1; // The back will start from the I-1 bit of the array m, record the value of the I-1 while (I) // find the number of I bits that meet the condition {for (Int J = 9; j> = 1 &&! Falg; j --) {S = sum; If (sum % J = 0) {falg = true; m [p ++] = J; sum/= J ;}} if (S = sum & sum> = 10) {return-1 ;}-- I; falg = false ;}for (; r >=0; r --) {num = num * 10 + M [R];} return num;} int main () {int N; // For (;) // {CIN> N; int sum = func (n); cout <sum <Endl; //} system ("pause"); Return 0 ;}
Running result:

The question is from the network.

A written examination question

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.