require'prime' n,x=gets.split.map &:to_i a=(x+1).prime_division.map{|k,v|(0..v).map{|i|k**i}} b=a.pop.product(*a).map{|e|e.reduce :*}.sort_by(:-@)[0..-2] m={} f=->x,n,d,a{x==1&&n==0?1:m[[x,n,d]]||=->{r=0;(d...a.size).each{|i|x%a[i]>0||r+=f[x/a[i],n-1,i,a]};r}[]} p f[x+1,n,0,b]