import Foundation
func isPrimeNumber(_ n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<Int(sqrt(Double(n)) + 1) {
if n % i == 0 {
return false
}
}
return true
}
func solution(_ n:Int, _ k:Int) -> Int {
var converted = ""
var tmp = n
while tmp >= 1 {
converted += String(tmp % k)
tmp /= k
}
var convertedList = converted.reversed().map { String($0) }
print(convertedList.joined())
var answer = 0
var savedValue = ""
while !convertedList.isEmpty {
if convertedList.last == "0" {
convertedList.removeLast()
} else {
while let last = convertedList.last, last != "0" {
savedValue += String(convertedList.removeLast())
}
let reversedValue = savedValue.reversed().map { String($0) }.joined()
if let number = Int(reversedValue), number > 1, isPrimeNumber(number) {
answer += 1
}
savedValue = ""
}
}
return answer
}