Haskell Common Prime Divisors
commonPrimeDivisors :: [Int] -> [Int] -> Int
commonPrimeDivisors as bs = length (filter matches (zip as bs))
  where
    matches (x, y) =
      let d = gcd x y
      in strip x d == 1 && strip y d == 1

    strip n m
      | n == 1    = 1
      | d == 1    = n
      | otherwise = strip (n `div` d) m
      where
        d = gcd n m

This checks whether two numbers are built from the same prime factors by repeatedly dividing out their shared parts.