-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGcd_or_Hcf.py
66 lines (51 loc) · 1.21 KB
/
Gcd_or_Hcf.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#method to compute gcd ( recursion )
#Native methiod to find GCD or HCF
#Eludes method to find GCD or HCF
def ComputeGCD(a,b):
if b==0:
return a
else:
return ComputeGCD(b,a%b)
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
print(ComputeGCD(num1,num2))
#******************************************
##Logic For GCD:
##Elude's or Eludeion's rule to calculate GCD:
##a = b*x + (a%b)
##64 = 48 * x + reminder
##64 = 48*1 + 16 --- a = b*x + (a%b)
##48=16*x + reminder --- a=b, b = a%b
##48={~16~} *3 + 0 ---when b = a%b = 0
##48=48 ---then the diviser is Greatest common deviser
##Therefore 16 is GCD Here
#******************************************
##Test cases:
##Case 1:
##I/p:
##Enter first number: 48
##Enter second number: 64
##O/p:
## 16
##
##Case 2:
##I/p:
##Enter first number: 250
##Enter second number: 30
##O/p:
## 10
##
##Case 3:
##I/p:
##Enter first number: 12
##Enter second number: 14
##O/p:
## 2
##
##Case 4:
##I/p:
##Enter first number: 21
##Enter second number: 17
##O/p:
## 1
#******************************************