#include <cstdio>
#include <map>

using namespace std;

typedef pair<int, int> frac;


frac sub(frac a, int den) {
	return frac(a.first * den - a.second, a.second * den);
}

int count(frac x, int acc, int max, int den, int n) {
	if (x.first == 0) return 1;
	if (n == 0) return 0;

	int result = 0;
	for (int i = den; acc * i <= max; i++) {
		frac y = sub(x, i);
		result += count(y, acc * i, max, i, n - 1);
	}

	return result;
}

int main() {
	while (true) {
		int p, q, a, n;

		scanf("%d %d %d %d", &p, &q, &a, &n);

		if (p == 0) break;

		printf("%d\n", count(frac(p, q), 1, a, 1, n));
	}
	return 0;
}