Skip to content

Commit

Permalink
solve(programmers): LV2_181187_두 원 사이의 정수 쌍_kt
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Mar 14, 2024
1 parent 2f7dace commit c741279
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/programmers/level_1/수학/두_원_사이의_정수_쌍.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package programmers.level_1.수학

import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt

class 두_원_사이의_정수_쌍 {
fun solution(r1: Int, r2: Int): Long {
var answer: Long = 0
val r22 = r2.toLong() * r2.toLong()
val r11 = r1.toLong() * r1.toLong()

for (x in 1..r2) {
val biy = floor(sqrt((r22 - x.toLong() * x).toDouble())).toLong()
val sy = if (x >= r1) 0 else ceil(sqrt((r11 - x.toLong() * x).toDouble())).toLong()
answer += biy - sy + 1
}

return answer * 4
}
}

0 comments on commit c741279

Please sign in to comment.