(n, p, k, zeros=False)
Returns a generator for finding k-tuples `(n_{1}, n_{2}, . . . n_{k})` such
    that `n = n_{1}^p + n_{2}^p + . . . n_{k}^p`.

    Here `n` is a non-negative integer. StopIteration exception is raised after
    all the solutions are generated, so should always be used within a try-
    catch block.

    Usage
    =====

    ``power_representation(n, p, k, zeros)``: Represent number ``n`` as a sum
    of ``k``, ``p``th powers. If ``zeros`` is true, then the solutions will
    contain zeros.

    Examples
    ========

    >>> from sympy.solvers.diophantine import power_representation
    >>> f = power_representation(1729, 3, 2) # Represent 1729 as a sum of two cubes
    >>> next(f)
    (12, 1)
    >>> next(f)
    (10, 9)
Returns a generator for finding k-tuples `(n_{1}, n_{2}, . . . n_{k})` such
    that `n = n_{1}^p + n_{2}^p + . . . n_{k}^p`.
Returns a generator for finding k - tuples ( n_ { 1 } n_ { 2 } . . . n_ { k } ) such that n = n_ { 1 } ^p + n_ { 2 } ^p + . . . n_ { k } ^p .
def power_representation(n, p, k, zeros=False):
    """
    Returns a generator for finding k-tuples `(n_{1}, n_{2}, . . . n_{k})` such
    that `n = n_{1}^p + n_{2}^p + . . . n_{k}^p`.

    Here `n` is a non-negative integer. StopIteration exception is raised after
    all the solutions are generated, so should always be used within a try-
    catch block.

    Usage
    =====

    ``power_representation(n, p, k, zeros)``: Represent number ``n`` as a sum
    of ``k``, ``p``th powers. If ``zeros`` is true, then the solutions will
    contain zeros.

    Examples
    ========

    >>> from sympy.solvers.diophantine import power_representation
    >>> f = power_representation(1729, 3, 2) # Represent 1729 as a sum of two cubes
    >>> next(f)
    (12, 1)
    >>> next(f)
    (10, 9)
    """
    if p < 1 or k < 1 or n < 1:
        raise ValueError("Expected: n > 0 and k >= 1 and p >= 1")

    if k == 1:
        if perfect_power(n):
            yield (perfect_power(n)[0],)
        else:
            yield tuple()

    elif p == 1:
        for t in partition(n, k, zeros):
            yield t

    else:
        l = []
        a = integer_nthroot(n, p)[0]

        for t in pow_rep_recursive(a, k, n, [], p):
                yield t

        if zeros:
            for i in xrange(2, k):
                for t in pow_rep_recursive(a, i, n, [], p):
                    yield t + (0,) * (k - i)
def power_representation ( n , p , k , zeros = False ) : if p < 1 or k < 1 or n < 1 : raise ValueError ( "Expected: n > 0 and k >= 1 and p >= 1" ) if k == 1 : if perfect_power ( n ) : yield ( perfect_power ( n ) [ 0 ] , ) else : yield tuple ( ) elif p == 1 : for t in partition ( n , k , zeros ) : yield t else : l = [ ] a = integer_nthroot ( n , p ) [ 0 ] for t in pow_rep_recursive ( a , k , n , [ ] , p ) : yield t if zeros : for i in xrange ( 2 , k ) : for t in pow_rep_recursive ( a , i , n , [ ] , p ) : yield t + ( 0 , ) * ( k - i )