#include<iostream>
using namespace std;

int p,q,a,n;

int dfs(int i,int x,int y,int m){
	int c=p*y-x*q;
	if(m==n||!c)return !c;
	if(c<0)return 0;
	int res=0;
	for(;i*y<=a;i++)res+=dfs(i,x*i+y,y*i,m+1);
	return res;
}
int main(){
	while(cin>>p>>q>>a>>n,p|q|a|n){
		cout<<dfs(1,0,1,0)<<endl;
	}
	return 0;
}