Let b >= 2, n >= 0. Let f(n,b) be the smallest nonnegative base-b numeral whose digital product is n. The value of f(b,0) and f(b,1) depend on whether we use the standard base-b representation of 0 ("0") or the purist representation ("", the null string). In the form case f(b,0) = "0" and f(b,1) = "1" while in the latter f(b,0) = "10" and f(b,1) = "" (whose digital product is technically 1). Either way, f(b,0) and f(b,1) are easy to compute and prove. The values of f(b,n) for n >= 2 are unaffected by this choice of representation. My stupid question is about computing f(b,n). In a recent program, I used the following algorithm: // Return the smallest base-b numeral whose digital product is n, or "-" if no such numeral. // Assumes purist base-b representation for simplicity function f(integer n, integer b) { // Handle zero if (n == 0) return "10"; // Start with null numeral numeral = ""; // For each base-b digit starting at the largest down to 2 for (integer digitValue = b-1; digitValue >= 2; digitValue--) { // While this digit divides n while (n%digitValue == 0) { // Divide digit out of n n /= digitValue; // Prepend base-b digit to numeral numeral = digit(digitValue, b) || numeral; } } // If n has factors that are not base-b digits, it is not a digital product if (n > 1) return "-"; // Return the numeral we built return numeral; } In effect, I went through the base-b digits in reverse order, each time dividing n by the digit as many times as possible, and took the dividing digits in reverse order as the ostensible smallest number with digital product n. Modulo probable errors in this hand-written pseudocode, is this algorithm correct? Does it actually return the smallest base-b numeral with digital product n? If so, how do we prove this? If not, does it work for some bases and not for others? Which bases does it work for? Does it work for base 10, as suggested by empirical testing I have done?