编辑代码

func z(_ num : Int) -> [Int]{
    var ret : [Int] = []
    var bul = Array(repeating:false, count:num+1)
    for index in 2...num{
        if(bul[index] == true){
            continue
        }
        var i = index + index
        while i <= num{
            bul[i] = true
            i += index
        }
        ret.append(index)
    }
    return ret
}

print(z(50))