GCD & LCM - Number Theory - Python

preview_player
Показать описание
Welcome to a new Coding Video!!!
----------------------------------------------------------------------------------------------------------------------------

If you like my content, please SUBSCRIBE, Hit the notification bell, and SHARE.
Thank you for your support!!
----------------------------------------------------------------------------------------------------------------------------

For private request, basic desktop applications, or just motivation, don't hesitate to contact me at:
----------------------------------------------------------------------------------------------------------------------------

Explanation

1. GCD
The GCD is the biggest number that can evenly divide both a and b
To find the GCD, you could use an iterative version, and you could use the recursive
version that we will explain here

GCD(a, b) is
a if b == 0
GCD(b, a % b) otherwise

That's it

2. LCM
The LCM is the smallest common multiple of the two numbers a and b
An easy way to calculate the LCM is to use the GCD we wrote earlier

LCM(a, b) = a / GCD(a, b) * b

Notice that we divided before multiplying to avoid overflow in case of
huge numbers

----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------

Tags
#Python #Math #GCD_LCM
Рекомендации по теме
join shbcf.ru