from functools import reduce
from math import sqrt


def factors(n):
    """
    Finds all factors for a given number.
    Copied from https://stackoverflow.com/a/19578818
    :param n: some integer
    :return: set with all factors of n
    """

    step = 2 if n % 2 else 1
    return set(
        reduce(
            list.__add__,
            ([i, n // i] for i in range(1, int(sqrt(n)) + 1, step) if n % i == 0),
        )
    )