STUDYING/Algorithm
[Programmers] 멀쩡한 사각형
EOZIN
2021. 9. 27. 00:32
728x90
https://programmers.co.kr/learn/courses/30/lessons/62048
import Foundation
func solution(_ w: Int, _ h: Int) -> Int64{
let gcd = GCD(w, h)
let smallW = w/gcd
let smallH = h/gcd
let cutRectangle = (smallW + smallH - 1) * gcd
return Int64(w * h - cutRectangle)
}
func GCD(_ min: Int, _ max: Int) -> Int {
let remain = min % max
if remain == 0 {
return max
} else {
return GCD(max, remain)
}
}