Map reducing using gcds and lcms