Created
September 15, 2018 04:31
-
-
Save rurumimic/d96be20d0e06311d099896bfcbd32eef to your computer and use it in GitHub Desktop.
GCD & LCM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func gcd(_ p: Int, _ q: Int) -> Int { | |
return q == 0 ? p : gcd(q, p % q) | |
} | |
func lcm(_ p: Int, _ q: Int) -> Int { | |
return p / gcd(p, q) * q | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment