#include <stdio.h>
void memorec(double p_q,int beforeDenom,int prod,int count);
int ans = 0;
int p,q,a,n;

int main() {
  while(1){
    scanf("%d",&p);
    scanf("%d",&q);
    scanf("%d",&a);
    scanf("%d",&n);
    if(p == 0 && q == 0 && a == 0 && n == 0) return 0;
    memorec((double)p/(double)q,1,1,1);
    printf("%d\n",ans);
  }
}

void memorec(double p_q,int beforeDenom,int prod,int count){
  double denominator = beforeDenom;
  double result;
  while(1){
    if(prod*denominator>a) return;
    result = p_q - 1/denominator;
    if(result < 0.000001 && result > -0.000001){
      ans++;
      denominator++;
      continue;
    }
    if(result > 0){
      if(count+1 > n) return;
      memorec(result,denominator,prod*denominator,count+1);
    }
    denominator++;
  }
}