-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexponial.py
More file actions
44 lines (38 loc) · 858 Bytes
/
exponial.py
File metadata and controls
44 lines (38 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Exponial
# Author: Debbie Macrohon
# Description: using modular exponentiation and euler's totient
#
vars = [int(i) for i in input().split(" ")]
n = vars[0]
m = vars[1]
def rec(num):
if num==1:
return num
elif num <=5:
z = rec(num-1)%m
# return (num**(z+m))%m
return (num**z)%m
else:
z =(num**(rec(num-1)))%phi(m)
return z
# return (num**(z+m))%m
#print(phi(m))
#return (num**(phi(m)+z))%m
def gcd(a, b):
if (a == 0):
return b
return gcd(b % a, a)
# A simple method to evaluate
# Euler Totient Function
def phi(n):
result = 1
for i in range(2, n):
if (gcd(i, n) == 1):
result+=1
return result
if (n > 5):
z = rec(n)
#print(z)
print((n**(phi(m)+z))%m)
else:
print(rec(n))