Previous Up Next

2.6.26  Legendre symbol : legendre_symbol

If n is prime, we define the Legendre symbol of a written (a/n) by :




a
n



=



0if a=0 modn 
1if  a ≠ 0 modn  and if  a=b2 modn
−1if  a ≠ 0 modn  and if  a ≠ b2 modn

Some properties

legendre_symbol takes two arguments a and n and returns the Legendre symbol (a/n).
Input :

legendre_symbol(26,17)

Output :

1

Input :

legendre_symbol(27,17)

Output :

-1

Input :

legendre_symbol(34,17)

Output :

0

Previous Up Next