require 'mathn'

def f(x, n, a, i)
  return 1 if x == 0
  return 0 if n == 0
  return 0 if i > a
  if i * i > a
    return x.numerator == 1 && i <= x.denominator && x.denominator <= a.to_i ? 1 : 0
  end
  t = f(x, n, a, i + 1)
  loop do
    x -= 1 / i
    n -= 1
    a /= i
    break if x < 0 || n < 0 || a < 1
    t += f(x, n, a, i + 1)
  end
  t
end

loop do
  p, q, a, n = gets.split.map(&:to_i)
  break if p == 0
  p f(p / q, n, a, 1)
end

