require "prime"
max = 1120
arr = Array.new(max + 1){Hash.new(0)}
Prime.each(max){|prime|
    (max - prime).downto(0){|i|
        arr[i].each{|k, v|
            arr[prime + i][k + 1] += v if k <= 14
        }
    }
    arr[prime][1] += 1
}

while true
    n, k = gets.chomp.split.map(&:to_i)
    break if [n, k] == [0, 0]
    puts arr[n][k]
end
