2024-10-20 21:36:32 +02:00
|
|
|
from gmpy2 import mpz
|
2024-10-19 20:16:04 +02:00
|
|
|
|
2024-10-20 21:36:32 +02:00
|
|
|
a = input("Podaj podstawę (b): ")
|
|
|
|
b = input("Podaj wykładnik (k): ")
|
|
|
|
n = input("Podaj moduł (n): ")
|
2024-10-19 20:16:04 +02:00
|
|
|
|
2024-10-20 21:36:32 +02:00
|
|
|
a = mpz(a)
|
|
|
|
b = mpz(b)
|
|
|
|
n = mpz(n)
|
2024-10-19 20:16:04 +02:00
|
|
|
|
2024-10-20 21:36:32 +02:00
|
|
|
wynik = mpz(1)
|
|
|
|
baza = a % n
|
2024-10-19 20:16:04 +02:00
|
|
|
|
2024-10-20 21:36:32 +02:00
|
|
|
for i in range(b.bit_length()):
|
2024-10-19 20:16:04 +02:00
|
|
|
if b.bit_test(i):
|
2024-10-20 21:36:32 +02:00
|
|
|
wynik = (wynik * baza) % n
|
|
|
|
baza = (baza * baza) % n
|
2024-10-19 20:16:04 +02:00
|
|
|
|
2024-10-20 21:36:32 +02:00
|
|
|
print(f"Wynik: {wynik}")
|