commit 7dac33cc1adce00b27ad3ca0e5cc7a4f0dbc5132 Author: serr Date: Fri Jan 10 20:57:45 2025 +0300 _ diff --git a/Legendre_symbol.py b/Legendre_symbol.py new file mode 100644 index 0000000..7a7bcf8 --- /dev/null +++ b/Legendre_symbol.py @@ -0,0 +1,15 @@ +import sys, re + +# Возвращает абсолютно наименьший вычет числа a по модулю числа b +def v(a, b): + r1 = a % b + r2 = r1 - b + return r1 if abs(r1) < abs(r2) else r2 + +def solve(a, p): + stop_i = (p-1)>>1 + 1 + cnt = sum(1 for i in range(1, stop_i) if v(a*i, p) < 0) + return pow(-1, cnt) + +f = re.fullmatch(r'(\d+)/(\d+)', sys.argv[1]).groups() +print(solve(int(f[0]), int(f[1]))) \ No newline at end of file