https://www.acmicpc.net/problem/1929
[난이도] Silver2
[유형] 에라토스테네스의 체
[풀이]
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
fun main() = with(BufferedReader(InputStreamReader(System.`in`))){
var ip = readLine().split(' ')
var n=ip[0].toInt()
var m=ip[1].toInt()
var notPrime = BooleanArray(1000001)
notPrime[1]=true
for(i in 2..m){
if (notPrime[i]) continue
var j = i*2
while(j<=m){
notPrime[j]=true
j+=i
}
}
for(i in n..m) if(!notPrime[i]) println(i)
}
https://github.com/has2/Problem-Solving/blob/master/boj-solved.ac/Silver2/1929.cpp
'Problem-Solving > BOJ' 카테고리의 다른 글
[BOJ/백준][Silver3] 1676 : 팩토리얼 0의 개수 (Kotlin) (0) | 2021.05.18 |
---|---|
[BOJ/백준][Silver1] 6588 : 골드바흐의 추측 (Kotlin) (0) | 2021.05.18 |
[BOJ/백준][Silver3] 10799 : 쇠막대기 (Kotlin) (0) | 2021.05.18 |
[BOJ/백준][Silver4] 10845 : 큐 (Kotlin) (0) | 2021.05.18 |
[BOJ/백준][Silver4] 10845 : 큐 (Kotlin) (0) | 2021.05.18 |