-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solve(programmers): LV2_181187_두 원 사이의 정수 쌍_kt
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |