Skip to content

Commit

Permalink
solve: 멀쩡한 사각형
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Apr 20, 2024
1 parent ed7e24e commit 1e4b44f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/kotlin/heejik/59week/멀쩡한 사격형.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package heejik.`59week`

class Solution {
fun solution(w: Int, h: Int): Long {
val gcd = getGcd(w, h)

val smallW: Long = (w.toLong() / gcd)
val smallH: Long = (h.toLong() / gcd)

val liveRectCnt: Long = (smallH - 1) * (smallW - 1)
val removeRectCnt: Long = (smallH * smallW) - liveRectCnt

return (w.toLong() * h.toLong()) - (removeRectCnt * gcd)
}

private fun getGcd(a: Int, b: Int): Int {
if (b == 0) return a
return getGcd(b, a % b)
}
}

fun main() {
Solution().solution(100000000, 99999999).also {
println(it)
}
}

0 comments on commit 1e4b44f

Please sign in to comment.