#include<stdio.h>
#include<stdlib.h>

int func(int p, int q, double a, int n, int 1)
{
    int i;
    int b=0;
    
    if(n>0&&p>0){
        for(i=1;i<=a;i++){
            if(p*i==q){
                b++;
            }
            b+=func(p*i-q, q*i, a/i, n-1, i);
        }
    }
    return b;
}

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