https://school.programmers.co.kr/learn/courses/30/lessons/92335?language=swift#
func solution(_ n:Int, _ k:Int) -> Int {
let radix = String(n, radix: k).split(separator: "0").map{ Int($0)! }
func isPrime(_ value: Int) -> Bool {
if value == 1 { return false }
for i in stride(from: 2, to: Int(sqrt(Double(value))) + 1, by: +1) {
if value % i == 0 {
return false
}
}
return true
}
return radix.filter{ isPrime($0) }.count
}
[프로그래머스] 압축 (0) | 2023.12.26 |
---|---|
[프로그래머스] 네트워크 (1) | 2023.12.25 |
[프로그래머스] 타겟 넘버 (0) | 2023.12.21 |
[프로그래머스] 뉴스 클러스터링 (0) | 2023.12.21 |
[프로그래머스] 피로도 (0) | 2023.12.20 |