Java program to print nearest element with at least one common prime factor .
import java . io . * ; import java . util . * ; class GFG { static int MAX = 100001 ; static int INF = Integer . MAX_VALUE ; static int [ ] primedivisor = new int [ MAX ] ; static int [ ] dist = new int [ MAX ] ; static int [ ] pos = new int [ MAX ] ; static int [ ] divInd = new int [ MAX ] ; static ArrayList < ArrayList < Integer > > divisors = new ArrayList < ArrayList < Integer > > ( ) ;