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