Find smallest number with given digits and sum of digits | Function to print minimum integer having only digits P and Q and the sum of digits as N ; If Q is greater that P then swap the values of P and Q ; If P and Q are both zero or if Q is zero and N is not divisible by P then there is no possible integer which satisfies the given conditions ; Loop to find the maximum value of count_P that also satisfy P * count_P + Q * count_Q = N ; If N is 0 , their is a valid integer possible that satisfies all the requires conditions ; Print Answer ; Driver Code ; Function Call
def printMinInteger ( P , Q , N ) : NEW_LINE INDENT if ( Q > P ) : NEW_LINE INDENT t = P NEW_LINE P = Q NEW_LINE Q = t NEW_LINE DEDENT if ( Q == 0 and ( P == 0 or N % P != 0 ) ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT count_P = 0 NEW_LINE count_Q = 0 NEW_LINE while ( N > 0 ) : NEW_LINE INDENT if ( N % P == 0 ) : NEW_LINE INDENT count_P += N / P NEW_LINE N = 0 NEW_LINE DEDENT else : NEW_LINE INDENT N = N - Q NEW_LINE count_Q += 1 NEW_LINE DEDENT DEDENT if ( N == 0 ) : NEW_LINE INDENT for i in range ( count_Q ) : NEW_LINE INDENT print ( Q , end = " " ) NEW_LINE DEDENT for i in range ( int ( count_P ) ) : NEW_LINE INDENT print ( P , end = " " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE DEDENT DEDENT N = 32 NEW_LINE P = 7 NEW_LINE Q = 4 NEW_LINE printMinInteger ( P , Q , N ) NEW_LINE