### subroutines

def count_rec(pi, qi, ai, ni, q0 = 1)
  if pi == 0
    return 1
  end

  if ni <= 0
    return 0
  end

  c = 0

  for q in (q0..ai)
    p1 = pi * q - qi
    next if p1 < 0
    q1 = qi * q
    a1 = ai / q
    c += count_rec(p1, q1, a1, ni - 1, q)
  end

  #p [pi, qi, ai, ni, q0, c]
  c
end

### main

loop do
  pi, qi, ai, ni = gets.split.map(&:to_i)
  break if (pi | qi | ai | ni) == 0

  c = count_rec(pi, qi, ai, ni)
  puts c
end