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