Largest number made up of X and Y with count of X divisible by Y and of Y by X | Function to generate and return the largest number ; Store the smaller in Y ; Store the larger in X ; Stores respective counts ; If N is divisible by Y ; Append X , N times to the answer ; Reduce N to zero ; Reduce N by x ; Append Y , X times to the answer ; If number can be formed ; Otherwise ; Driver code
def largestNumber ( n , X , Y ) : NEW_LINE INDENT maxm = max ( X , Y ) NEW_LINE Y = X + Y - maxm NEW_LINE X = maxm NEW_LINE Xs = 0 NEW_LINE Ys = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( n % Y == 0 ) : NEW_LINE INDENT Xs += n NEW_LINE n = 0 NEW_LINE DEDENT else : NEW_LINE INDENT n -= X NEW_LINE Ys += X NEW_LINE DEDENT DEDENT if ( n == 0 ) : NEW_LINE INDENT while ( Xs > 0 ) : NEW_LINE INDENT Xs -= 1 NEW_LINE print ( X , end = ' ' ) NEW_LINE DEDENT while ( Ys > 0 ) : NEW_LINE INDENT Ys -= 1 NEW_LINE print ( Y , end = ' ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT n = 19 NEW_LINE X = 7 NEW_LINE Y = 5 NEW_LINE largestNumber ( n , X , Y ) NEW_LINE