Skip to content

Instantly share code, notes, and snippets.

@rurumimic
Created September 15, 2018 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rurumimic/d96be20d0e06311d099896bfcbd32eef to your computer and use it in GitHub Desktop.
Save rurumimic/d96be20d0e06311d099896bfcbd32eef to your computer and use it in GitHub Desktop.
GCD & LCM
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