#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

#define cerr if(0) cerr

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Bunsu {
private:
	void setValue() {
		value = (double)bunshi / bunbo;
	}

	void tsubun() {
		for (int e : primes) {
			if (e > min(bunshi, bunbo)) break;
			while (bunshi % e == 0 && bunbo % e == 0) {
				bunshi /= e;
				bunbo /= e;
			}
		}
	}

	static void init() {
		bool prime[1000000];
		memset(prime, true, sizeof(prime));

		for (int i = 2; i < 1000000; i++) {
			if (!prime[i]) continue;

			primes.push_back(i);
			for (int j = 2 * i; j < 1000000; j += i) {
				prime[j] = false;
			}
		}

		initialized = true;
	}

public:
	int bunshi;
	int bunbo;
	double value;

	static bool initialized;
	static vector<int> primes;

	Bunsu(int bunshi, int bunbo) {
		if (!initialized) {
			init();
		}

		this->bunshi = bunshi;
		this->bunbo = bunbo;
		tsubun();
		setValue();
	}

	Bunsu operator + (Bunsu obj) {
		Bunsu cp = Bunsu(bunshi, bunbo);
		obj.bunshi *= cp.bunbo;
		cp.bunshi *= obj.bunbo;

		Bunsu ret = Bunsu(cp.bunshi + obj.bunshi, cp.bunbo * obj.bunbo);
		ret.tsubun();
		return ret;
	}

	Bunsu operator - (Bunsu obj) {
		Bunsu cp = Bunsu(bunshi, bunbo);
		obj.bunshi *= cp.bunbo;
		cp.bunshi *= obj.bunbo;

		Bunsu ret = Bunsu(cp.bunshi - obj.bunshi, cp.bunbo * obj.bunbo);
		ret.tsubun();

		return ret;
	}

	Bunsu operator * (Bunsu obj) {
		Bunsu ret = Bunsu(bunshi * obj.bunshi, bunbo * obj.bunbo);
		ret.tsubun();
		return ret;
	}

	Bunsu operator / (Bunsu obj) {
		Bunsu ret = Bunsu(bunshi * obj.bunbo, bunbo * obj.bunshi);
		ret.tsubun();
		return ret;
	}

	bool operator <= (Bunsu obj) {
		Bunsu cp = Bunsu(bunshi, bunbo);
		obj.bunshi *= cp.bunbo;
		cp.bunshi *= obj.bunbo;

		return cp.bunshi <= obj.bunshi;
	}
};

bool Bunsu::initialized = false;
vector<int> Bunsu::primes = vector<int>();

int a;

int solve(Bunsu left, int na, int n, int prev) {
	cerr << "left:" << left.bunshi << "/" << left.bunbo << "  na:" << na << "  n:" << n << "  prev:" << prev << endl;
	if (na * left.bunbo > a) {
		return 0;
	}
	if (n == 1) {
		if (na * left.bunbo > a) return 0;
		if (left.bunshi == 1) {
			return 1;
		}
		return 0;
	}

	int ret = 0;
	if (left.bunshi == 1 && left.bunbo >= prev) {
		ret++;
	}

	for (int bunbo = prev; ; bunbo++) {
		Bunsu now = Bunsu(1, bunbo);
		if (left <= now) continue;
		if ((left / now).value >= n + 0.000000001) {
			break;
		}
		if (na * bunbo > a) break;
		ret += solve(left - now, na * bunbo, n - 1, bunbo);
	}

	return ret;
}

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

		if (p == 0) break;

		cout << solve(Bunsu(p, q), 1, n, 1) << endl;
	}

    return 0;
}

Measured memory_bytes: 4776