Python math.gcd
dev.to·6d·
Discuss: DEV

(10,2) => 2
(3, 5) => 1

def gcd(a,b):
    if a < b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

import math

assert gcd(13, 2436) == 1 assert gcd(10, 2) == 2 assert math.gcd(13, 2436) == 1 assert math.gcd(10, 2) == 2

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help