23 lines
443 B
Python
23 lines
443 B
Python
# obliczyć pierwiastek kwadratowy w fi
|
|
|
|
p = int(input("Podaj p -> liczba pierwsza modulo: "))
|
|
b = int(input("Podaj b -> reszta kwadratowa: "))
|
|
|
|
|
|
def potegowanieimod(b, k, n):
|
|
y = 1
|
|
while k > 0:
|
|
if k & 1:
|
|
y = y*b % n
|
|
b = b**2 % n
|
|
k = k >> 1
|
|
return y
|
|
|
|
|
|
for i in range(1, p):
|
|
a = potegowanieimod(i, (p-1)//2, p)
|
|
if a == b:
|
|
print("Result: {}".format(i))
|
|
|
|
|
|
#dane testowe to p=5 i b=4 |