2023-12-13 legendre記号 平方剰余 平方剰余 def legendre_symbol(a, p): ls = pow(a, (p - 1)//2, p) if ls == p - 1: return -1 return ls