object Main {
  var mul_limit = 12000
  var depth_limit = 7
  def dfs(p: Int, q: Int, depth: Int, sub: Int, mul: Int): Int = {
    p match {
      case 0 => 1
      case _ =>
        var ret = 0
        for{
          i <- (sub to mul_limit).takeWhile(x =>
            mul * x <= mul_limit &&
            (depth_limit - depth) * q >= p * x)
          if p * i >= q
        } ret += dfs(p * i - q, q * i, depth + 1, i, mul * i)
        ret
    }
  }
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var p, q = sc.nextInt
    mul_limit = sc.nextInt
    depth_limit = sc.nextInt
    while(p != 0) {
      println(dfs(p, q, 0, 1, 1))
      p = sc.nextInt
      q = sc.nextInt
      mul_limit = sc.nextInt
      depth_limit = sc.nextInt
    }
  }
}