Function to calculate all divisors of input array
function findDivisors ( arr , n ) { for ( let i = 0 ; i < MAX ; ++ i ) { pos [ i ] = divInd [ i ] = - 1 ; dist [ i ] = INF ; } for ( let i = 0 ; i < n ; ++ i ) { let num = arr [ i ] ; while ( num > 1 ) { let div = primedivisor [ num ] ; divisors [ i ] . push ( div ) ; while ( num % div == 0 ) { num = Math . floor ( num / div ) ; } } } } function nearestGCD ( arr , n ) {