require 'prime'

dp = 14.times.map{ [0] * 1121 }
primes = Prime.each.take_while{ |p| p < 1120 }
cnt = 0
primes.each do |p|
  ndp = dp.map(&:dup)
  ndp[0][p] = 1
  cnt.times do |i|
    (2..1120 - p).each do |k|
      ndp[i + 1][k + p] += dp[i][k]
    end
  end
  cnt += 1 if cnt < 13
  dp = ndp
end

loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  puts dp[k - 1][n]
end