$/=words;say (+^-$0*+^-$1,-2)[$0 gcd$1>1]/2