From 9ed39d08d1221073032c30cdbdc1d614aaf4f4bc Mon Sep 17 00:00:00 2001 From: yubin Date: Sun, 14 Jan 2024 16:36:15 +0900 Subject: [PATCH] =?UTF-8?q?solve(BOJ):=20G5=5F1456=5F=EA=B1=B0=EC=9D=98=5F?= =?UTF-8?q?=EC=86=8C=EC=88=98=5Fkt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\230_\354\206\214\354\210\230.kt" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "src/boj/G5_1456_\352\261\260\354\235\230_\354\206\214\354\210\230.kt" diff --git "a/src/boj/G5_1456_\352\261\260\354\235\230_\354\206\214\354\210\230.kt" "b/src/boj/G5_1456_\352\261\260\354\235\230_\354\206\214\354\210\230.kt" new file mode 100644 index 0000000..39df08a --- /dev/null +++ "b/src/boj/G5_1456_\352\261\260\354\235\230_\354\206\214\354\210\230.kt" @@ -0,0 +1,45 @@ +package boj + +import kotlin.math.pow +import kotlin.math.sqrt + +class BOJ1456() { + + + fun solve() { + val (a, b) = readln().split(" ").map { it.toLong() } + + val MAX = sqrt(b.toDouble()).toInt() + val isPrime = BooleanArray(MAX + 1) { true } + var count = 0 + isPrime[0] = false + isPrime[1] = false + + for (i in 2..MAX / 2) { + if (!isPrime[i]) continue + var mul = 2 + while (true) { + isPrime[i * mul] = false + mul++ + if (i * mul > MAX) break + } + } + + for (i in 2..MAX) { + if (!isPrime[i]) continue + var exp = 2 + while (true) { + val num = i.toDouble().pow(exp) + if (num >= a && num <= b) count++ + else if (num > b) break + exp++ + } + } + + println(count) + } +} + +fun main() { + BOJ1456().solve() +} \ No newline at end of file