#include <stdio.h>

int p, q, a, n;
int den[7];
int num;

void solve(int level, int mul, int bef)
{
    int i;
    int r_den, r_num;
    r_num = 0;
    r_den = 1;
    for(i = 0; i < level; i++){
        r_den *= den[i];
        int j;
        int temp = 1;
        for(j = 0; j < level; j++){
            if(i == j)
                continue;
            temp *= den[j];
        }
        r_num += temp;
    }

    if(r_num % p == 0 && r_den % q == 0){
        if(r_num / p == r_den / q){
            //for(i = 0; i < level; i++){
            //    printf("1/ %d, ", den[i]);
            //}
            //printf("\n");

            num++;
            return ;
        }
    }

    if(level < 7){
        for(i = bef; i * mul <= a; i++){
            den[level] = i;
            solve(level + 1, i * mul, i);
        }
    }
}

int main(void)
{
    while(1){
        scanf("%d %d %d %d", &p, &q, &a, &n);
        if(p == 0 && q == 0 && a == 0 && n == 0)
            break;

        int i;
        for(i = 0; i < 7; i++)
            den[i] = 0;
        num = 0;
        solve(0, 1, 1);

        //for(i = 1; i <= a; i++){
        //    den[0] = i;
        //    solve(1, i, i);
        //}

        printf("%d\n", num);
    }

    return 0;
}