728x90
λ°μν
Problem
Solution
1. nμ kμ§μλ‘ λ°κΎΌλ€.
let change = String(n,radix: k)
2. λ°κΎΌ λ¬Έμλ₯Ό 0μ κΈ°μ€μΌλ‘ λλλ€.
let numbers = change.split(separator: "0")
3. μμμΈμ§ νλ³νλ€.
func isPrimeNumber(_ n:Int) -> Bool {
if n == 1 { return false }
if n == 2 || n == 3 {return true}
let sq = Int(sqrt(Double(n)))
for i in 2...sq {
if n%i == 0 {
return false
}
}
return true
}
4. μμμΈ μ«μμ κ°―μλ₯Ό λ°ννλ€.
return numbers.filter{isPrimeNumber(Int($0)!)}.count
Source Code
728x90
λ°μν
'π Problem Solution > Programmers' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Swift] 2022 KAKAO BLIND RECRUITMENT μκΆλν (1) | 2022.01.19 |
---|---|
[Swift] 2022 KAKAO BLIND RECRUITMENT μ£Όμ°¨ μκΈ κ³μ° (0) | 2022.01.19 |
[Swift] 2022 KAKAO BLIND RECRUITMENT μ κ³ κ²°κ³Ό λ°κΈ° (0) | 2022.01.19 |
[Swift] 2020 KAKAO BLIND RECRUITMENT κ°μ¬ κ²μ (0) | 2022.01.03 |
[Swift] νλ‘κ·Έλλ¨Έμ€ μ§κ²λ€λ¦¬ (with μ¬μ΄ νμ΄ ν¬ν¨) (0) | 2022.01.03 |
λκΈ