Hacker News new | ask | show | jobs
by alexkus 4966 days ago
https://en.wikipedia.org/wiki/Quadratic_residue also the Legendre symbol.

Also there's no need to consider numbers >= 40 when working mod 40

    47 * 47 (mod 40)

    = (40+7) * (40+7) (mod 40)

    40 * n = 0 (mod 40) for any integer n since 40*n will be a multiple of 40, so:-

    = 40*(40+7) + 7*(40+7) (mod 40)

    = 0 + 7*(40+7) (mod 40)

    = 7 * (40+7) (mod 40)

    = 7*7 + 7*40 (mod 40)

    = 7*7 + 0 (mod 40)

    = 7*7

    So n^2 (mod 40) = (n mod 40)^2 (mod 40).