Construct an array from its pair | 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
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function constructArr ( pair , n ) { let size = Math . floor ( ( 1 + Math . sqrt ( 1 + 8 * n ) ) / 2 ) ; let arr = new Array ( size ) ; arr [ 0 ] = Math . floor ( Math . sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ) ; for ( let i = 1 ; i < size ; i ++ ) arr [ i ] = Math . floor ( pair [ i - 1 ] / arr [ 0 ] ) ; printArr ( arr , size ) ; } let pair = [ 48 , 18 , 24 , 24 , 32 , 12 ] ; let n = pair . length ; constructArr ( pair , n ) ;