Construct an array from its pair | Java 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
class GFG { static void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } static void constructArr ( int pair [ ] , int n ) { int size = ( 1 + ( int ) Math . sqrt ( 1 + 8 * n ) ) / 2 ; int [ ] arr = new int [ size ] ; arr [ 0 ] = ( int ) Math . sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ; for ( int i = 1 ; i < size ; i ++ ) arr [ i ] = pair [ i - 1 ] / arr [ 0 ] ; printArr ( arr , size ) ; } public static void main ( String [ ] args ) { int pair [ ] = { 48 , 18 , 24 , 24 , 32 , 12 } ; int n = pair . length ; constructArr ( pair , n ) ; } }