From c7412797ba57e5c46c31128a72792c828a3683b4 Mon Sep 17 00:00:00 2001 From: yubin Date: Thu, 14 Mar 2024 16:21:14 +0900 Subject: [PATCH] =?UTF-8?q?solve(programmers):=20LV2=5F181187=5F=EB=91=90?= =?UTF-8?q?=20=EC=9B=90=20=EC=82=AC=EC=9D=B4=EC=9D=98=20=EC=A0=95=EC=88=98?= =?UTF-8?q?=20=EC=8C=8D=5Fkt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\240\225\354\210\230_\354\214\215.kt" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "src/programmers/level_1/\354\210\230\355\225\231/\353\221\220_\354\233\220_\354\202\254\354\235\264\354\235\230_\354\240\225\354\210\230_\354\214\215.kt" diff --git "a/src/programmers/level_1/\354\210\230\355\225\231/\353\221\220_\354\233\220_\354\202\254\354\235\264\354\235\230_\354\240\225\354\210\230_\354\214\215.kt" "b/src/programmers/level_1/\354\210\230\355\225\231/\353\221\220_\354\233\220_\354\202\254\354\235\264\354\235\230_\354\240\225\354\210\230_\354\214\215.kt" new file mode 100644 index 0000000..0a04416 --- /dev/null +++ "b/src/programmers/level_1/\354\210\230\355\225\231/\353\221\220_\354\233\220_\354\202\254\354\235\264\354\235\230_\354\240\225\354\210\230_\354\214\215.kt" @@ -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 + } +} \ No newline at end of file