#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int p,q,a,n;

int rec(int u = 0,int d = 1,int cou = 0,int from = 1){
	if(p * d == u * q) return 1;
	if(p * d < u * q) return 0;
	if(cou == n) return 0;
	int sum = 0;
	for(int i = from;i * d <= a;i++){
		sum += rec(u * i + d,i * d,cou + 1,i);
	}
	return sum;
}

int main(){
	while(cin >> p >> q >> a >> n,q){
		cout << rec() << endl;
	}
}

