def quadratic_residues(p):
    """Returns the list of quadratic residues.

    Examples
    ========

    >>> quadratic_residues(7)
    [0, 1, 2, 4]

    """
    r = set()
    for i in range(p // 2 + 1):
        r.add(pow(i, 2, p))
    return sorted(r)
