Construct an array from its pair | Python3 implementation of the approach ; Utility function to print the array ; Function to generate the original array from the pair - product array ; First element of the resulting array ; Find all the other elements ; Print the elements of the generated array ; Driver code
from math import sqrt NEW_LINE def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT def constructArr ( pair , n ) : NEW_LINE INDENT size = int ( ( 1 + sqrt ( 1 + 8 * n ) ) // 2 ) ; NEW_LINE arr = [ 0 ] * ( size ) ; NEW_LINE arr [ 0 ] = int ( sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ) ; NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT arr [ i ] = pair [ i - 1 ] // arr [ 0 ] ; NEW_LINE DEDENT printArr ( arr , size ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT pair = [ 48 , 18 , 24 , 24 , 32 , 12 ] ; NEW_LINE n = len ( pair ) ; NEW_LINE constructArr ( pair , n ) ; NEW_LINE DEDENT