#include <stdio.h>

int p, q, a, n;

int solve(int level, int num, int den, int bef)
{
    int i;
    int ret = 0;

    for(i = bef; i * den <= a; i++){
        int left = p * den * i;
        int right = (num * i) + den;
        if(left < right * q)
            continue;
        if(left == right * q){
            ret++;
            continue;
        }
        if(level < 7)
            ret += solve(level + 1, right, den * i, i);
    }
    return ret;
}

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;
        int num = solve(0, 0, 1, 1);


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

    return 0;
}