factors :: Int -> Set Int
factors n =
  Set.unions $
    map (\r -> let r' = n `div` r in if r' <= 50 then Set.fromList [r, r'] else Set.singleton r') $
      filter (\r -> n `mod` r == 0) $
        takeWhile (\r -> r * r <= n) $
          [1 .. 50]
factors :: Int -> Set Int
factors n =
  Set.unions $
    map (\r -> let r' = n `div` r in if r' <= 50 then Set.fromList [r, r'] else Set.singleton r') $
      filter (\r -> n `mod` r == 0) $
        takeWhile (\r -> r * r <= n) $
          [1 .. 50]
factors n =
  Set.unions $
    map (\r -> let r' = n `div` r in if r' <= 50 then Set.fromList [r, r'] else Set.singleton r') $
      filter (\r -> n `mod` r == 0) $
        takeWhile (\r -> r * r <= n) $
          [1 .. 50]