Добавил:
SSU_CSIT
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:ПУА / 2PYA_3
.py # def phi(n):
# res = n
# i = 2
# while i * i <= n:
# if n % i == 0:
# while n % i == 0:
# n //= i
# res -= res // i
# else:
# i += 1
# if n > 1:
# res -= res //n
# return res
def phi(n):
res = 0
for i in range(n):
if NOD(n,i) == 1:
res += 1
return res
def NOD(a,b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
nod = a + b
return nod
a = int(input('a = '))
b = int(input('b = '))
m = int(input('m = '))
if NOD(a,m) == 1:
phi_m = phi(m)
a = a ** (phi_m - 1)
x = (b * a) % m
x = x % m
print(x)
else: print('Does not correct')
# res = n
# i = 2
# while i * i <= n:
# if n % i == 0:
# while n % i == 0:
# n //= i
# res -= res // i
# else:
# i += 1
# if n > 1:
# res -= res //n
# return res
def phi(n):
res = 0
for i in range(n):
if NOD(n,i) == 1:
res += 1
return res
def NOD(a,b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
nod = a + b
return nod
a = int(input('a = '))
b = int(input('b = '))
m = int(input('m = '))
if NOD(a,m) == 1:
phi_m = phi(m)
a = a ** (phi_m - 1)
x = (b * a) % m
x = x % m
print(x)
else: print('Does not correct')