ν°μ€ν 리 λ·°
π©π»π» λ¬Έμ
βπ» νμ΄
π¨ Go
// https://www.acmicpc.net/problem/2960
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, k int
fmt.Fscanln(reader, &n, &k)
fmt.Fprintln(writer, eratos(n, k))
}
func eratos(n, k int) (kth int) {
primeNumbers := initPrimeNumbers(n)
for i := 2; i < n+1; i++ {
if primeNumbers[i] {
for j := i; j < n+1; j += i {
if primeNumbers[j] {
primeNumbers[j] = false
k--
if k == 0 {
kth = j
return
}
}
}
}
}
return
}
func initPrimeNumbers(n int) []bool {
var primeNumbers = make([]bool, n+1)
for i := range primeNumbers {
primeNumbers[i] = true
}
return primeNumbers
}
π¨ Python3
# https://www.acmicpc.net/problem/2960
import sys
def eratos(n, k):
prime_numbers = [True for _ in range(n+1)]
kth = 0
for i in range(2, n+1):
if prime_numbers[i]:
for j in range(i, n+1, i):
if prime_numbers[j]:
prime_numbers[j] = False
k -= 1
if k == 0:
kth = j
return kth
return kth
if __name__ == "__main__":
n, k = list(map(int, sys.stdin.readline().split()))
print(eratos(n, k))
728x90
'dev > algorithm' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ / 11722λ² / κ°μ₯ κΈ΄ κ°μνλ λΆλΆ μμ΄ [Go][Python3] (0) | 2021.03.30 |
---|---|
BOJ / 10974λ² / λͺ¨λ μμ΄ [Go][Python3] (0) | 2021.03.29 |
BOJ / 1057λ² / ν λλ¨ΌνΈ [Go][Python3] (0) | 2021.03.27 |
BOJ / 11048λ² / μ΄λνκΈ° [Go][Python3] (0) | 2021.03.26 |
BOJ / 1991λ² / νΈλ¦¬ μν [Go][Python3] (0) | 2021.03.25 |
λκΈ
κΈ λ³΄κ΄ν¨
μ΅κ·Όμ λ¬λ¦° λκΈ
TAG
- MongoDB
- Macbook pro 2012 mid 13
- AWS
- Golang
- λ§₯λΆ μ κ·Έλ μ΄λ
- ν
- dp
- λͺ½κ³ λλΉ
- λΆν μ 볡
- λ°±μ€
- λ§₯λΆνλ‘
- μ΄λΆνμ
- λΈλ£¨νΈν¬μ€
- λ§₯λΆ
- baekjoon
- dfs
- BOJ
- Algorithm
- java
- ν΄μ맡
- python3
- νλ‘μ΄λμμ¬
- μκ³ λ¦¬μ¦
- μλ°
- ballet
- μ€ν
- λ°λ
- BFS
- go
- μκ°κ΅μ²΄
- Total
- Today
- Yesterday