Function to calculate all divisors of input array
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 ] . push_back ( div ) ; while ( num % div == 0 ) num /= div ; } } } void nearestGCD ( int arr [ ] , int n ) {