(f, K)
Efficiently factor polynomials `x**n - 1` and `x**n + 1` in `Z[x]`.

    Given a univariate polynomial `f` in `Z[x]` returns a list of factors
    of `f`, provided that `f` is in the form `x**n - 1` or `x**n + 1` for
    `n >= 1`. Otherwise returns None.

    Factorization is performed using using cyclotomic decomposition of `f`,
    which makes this method much faster that any other direct factorization
    approach (e.g. Zassenhaus's).

    References
    ==========

    1. [Weisstein09]_
Efficiently factor polynomials `x**n - 1` and `x**n + 1` in `Z[x]`.
Efficiently factor polynomials x ** n - 1 and x ** n + 1 in Z [ x ] .
def dup_zz_cyclotomic_factor(f, K):
    """
    Efficiently factor polynomials `x**n - 1` and `x**n + 1` in `Z[x]`.

    Given a univariate polynomial `f` in `Z[x]` returns a list of factors
    of `f`, provided that `f` is in the form `x**n - 1` or `x**n + 1` for
    `n >= 1`. Otherwise returns None.

    Factorization is performed using using cyclotomic decomposition of `f`,
    which makes this method much faster that any other direct factorization
    approach (e.g. Zassenhaus's).

    References
    ==========

    1. [Weisstein09]_

    """
    lc_f, tc_f = dup_LC(f, K), dup_TC(f, K)

    if dup_degree(f) <= 0:
        return None

    if lc_f != 1 or tc_f not in [-1, 1]:
        return None

    if any(bool(cf) for cf in f[1:-1]):
        return None

    n = dup_degree(f)
    F = _dup_cyclotomic_decompose(n, K)

    if not K.is_one(tc_f):
        return F
    else:
        H = []

        for h in _dup_cyclotomic_decompose(2*n, K):
            if h not in F:
                H.append(h)

        return H
def dup_zz_cyclotomic_factor ( f , K ) : lc_f , tc_f = dup_LC ( f , K ) , dup_TC ( f , K ) if dup_degree ( f ) <= 0 : return None if lc_f != 1 or tc_f not in [ - 1 , 1 ] : return None if any ( bool ( cf ) for cf in f [ 1 : - 1 ] ) : return None n = dup_degree ( f ) F = _dup_cyclotomic_decompose ( n , K ) if not K . is_one ( tc_f ) : return F else : H = [ ] for h in _dup_cyclotomic_decompose ( 2 * n , K ) : if h not in F : H . append ( h ) return H