Ask Your Question

Revision history [back]

Given that $(n + p) = n^2 \mbox{ mod } p$, you just have to compute the numbers $n^2 { mod } p$ for all integers between $0$ and $p-1$. If you want to avoid repetitions, you just have to put them in a set. Here is how:

sage: p = 17
sage: S = {n^2 % p for n in range(p)}
sage: S
{0, 1, 2, 4, 8, 9, 13, 15, 16}

sage: p = 123457
sage: S = {n^2 % p for n in range(p)}
sage: len(S)
61729

Given that $(n + p) = n^2 \mbox{ mod } p$, you just have to compute the numbers $n^2 { \mbox{ mod } p$ for all integers between $0$ and $p-1$. If you want to avoid repetitions, you just have to put them in a set. Here is how:

sage: p = 17
sage: S = {n^2 % p for n in range(p)}
sage: S
{0, 1, 2, 4, 8, 9, 13, 15, 16}

sage: p = 123457
sage: S = {n^2 % p for n in range(p)}
sage: len(S)
61729

Given that $(n + p) p)^2 = n^2 + 2np + p^2 = n^2 \mbox{ mod } p$, you just have to compute the numbers $n^2 \mbox{ mod } p$ for all integers between $0$ and $p-1$. If you want to avoid repetitions, you just have to put them in a set. Here is how:

sage: p = 17
sage: S = {n^2 % p for n in range(p)}
sage: S
{0, 1, 2, 4, 8, 9, 13, 15, 16}

sage: p = 123457
sage: S = {n^2 % p for n in range(p)}
sage: len(S)
61729