Skip to content

Commit

Permalink
2024-05-14 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed May 14, 2024
1 parent 3bb5812 commit b42bd35
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.sqrt

fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
var (head, tail) = 0 to 0
val n = br.readLine().toInt()
val primes = findPrimeNumbers(n)
var count = 0

while (head < primes.size && tail < primes.size) {
val sum = primes.subList(head, tail + 1).sum()
if (sum < n) {
tail++
continue
}
if (sum == n) {
count++
}
head++
}
println(count)
}

private fun findPrimeNumbers(rangeMax: Int): List<Int> {
return (2..rangeMax).filter {
isPrime(it)
}
}

private fun isPrime(num: Int): Boolean {
for (i in 2..sqrt(num.toDouble()).toInt()) {
if (num % i == 0) {
return false
}
}
return true
}

0 comments on commit b42bd35

Please sign in to comment.