import math


def divisors(n, non_trivial=False):
    """Return the set of divisors of n.  Setting non_trivial=True, returns all
    divisors except for 1 & n."""
    result = set()
    for i in range(1, int(math.sqrt(n)) + 1):
        quot, rem = divmod(n, i)
        if rem == 0:
            result.update({i, quot})
    res = sorted(list(result))
    if non_trivial:
        return res[1:-1]
    else:
        return res