-
Notifications
You must be signed in to change notification settings - Fork 4
/
9eulers.py
50 lines (39 loc) · 845 Bytes
/
9eulers.py
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
45
46
47
48
49
50
"""
Practical 9
Write a program to verify
ii) Eulers's Theorem
"""
import math
import time
import decimal
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
def phi(n):
count = 0
for i in range(0,n):
if(gcd(i,n)==1):
count = count + 1
return count
def euler(a,n,p):
lhs = float(math.pow(a,p))
rhs = float(lhs%n)
return lhs,rhs
aValue = int(input("Enter value for a: "))
bValue = int(input("Enter value for n: "))
start = time.time()
phi = phi(bValue)
e,f = euler(aValue,bValue,phi)
de = '%.2E'% decimal.Decimal(e)
print("a^phi(n)=1(mod n) i.e {} = {}".format(de,f))
end = time.time()
print("Running time = {}".format(end - start))
"""
Output
Enter value for a: 10
Enter value for n: 11
a^phi(n)=1(mod n) i.e 1.00E+10 = 1.0
Running time = 0.000361204147339
"""