Numbers = [0,1,2,3,4,5,6,7,8,9]
Combi = Array.new
(1..10).each{|t|  Combi << Numbers.permutation(t) }

def getSum(v)
  sum = 0
  v.size.times{|t| sum += (t + 1) * v[t] }
  return sum
end

loop do
  v = $stdin.gets.split(" ").map{|n| n.to_i}
  break if v[0] == 0
  c = 0
  
  Combi[v[0] - 1].to_a.each{|a| c += 1 if  getSum(a) == v[1]}
  p c
end