#include <stdio.h>

int p, q, a, n;
int num;

void solve(int level, int mul, int sum, int bef)
{
    int i;
    int r_den, r_num;
    
    //printf("now: %d / %d\n", sum, mul);

    if(sum % p == 0 && mul % q == 0){
        if(sum / p == mul / q){

            num++;
            return ;
        }
    }

    if(level < 7){
        for(i = bef; i * mul <= a; i++){
            int new_num = (sum * i) + mul;
            solve(level + 1, i * mul, new_num, 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;
        num = 0;
        solve(0, 1, 0, 1);


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

    return 0;
}