main
commit
7dac33cc1a
|
@ -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])))
|
Loading…
Reference in New Issue