import Foundation
let line = readLine()!.components(separatedBy: " ").map { Int($0)! }
var n = line[0]
var m = line[1]
func getGCD(n1: Int, n2: Int) -> Int {
if n2 == 0 {
return n1
} else {
return getGCD(n1: n2, n2: n1 % n2)
}
}
func getLCM(num1: Int, num2: Int) -> Int {
return num1 * num2 / getGCD(n1: num1, n2: num2)
}
print(getGCD(n1: n, n2: m))
print(getLCM(num1: n, num2: m))
반응형
'📝 코테 > BOJ' 카테고리의 다른 글
[Swift] 백준10773 (0) | 2023.03.27 |
---|---|
[Swift] 백준2775 (0) | 2023.03.27 |
[Swift] 백준2231 (0) | 2023.03.24 |
[Swift] 백준2164 (0) | 2023.03.24 |
[Swift] 백준1966 (0) | 2023.03.24 |