//#define NDEBUG #include #include #include #include #include #include #include #include #include using namespace std; #undef max #undef min #define max(x,y) ((x)>(y)?(x):(y)) #define min(x,y) ((x)<(y)?(x):(y)) #ifdef NDEBUG #define dprintf #else #define dprintf printf #endif int chomp(char *s) { int len; len = strlen(s); while(len > 0 && (s[len-1] == '\r' || s[len-1] == '\n')) s[--len] = '\0'; return len; } int cnt; int depth_lim; int seki_lim; int gcd(int n, int m) { int t; if (n < m) { t = n; n = m; m = t; } if (m == 0) return 0; while((t = n%m) != 0) { n = m; m = t; } return m; } void calc(int p,int q,int bunbo,int depth,int seki){ int x,y,tmp; if(depth >= depth_lim){ return; } if(seki >= seki_lim){ return; } for( ; bunbo*seki <= seki_lim; bunbo++) { x = bunbo*p-q; y = bunbo*q; if(x == 0){ cnt++; continue; } tmp = gcd(x,y); x /= tmp; y /= tmp; calc(x,y,bunbo,depth+1,bunbo*seki); } } int main() { int q,p; while(1){ scanf("%d %d %d %d",&p,&q,&seki_lim,&depth_lim); if(p == 0 && q == 0 && seki_lim == 0 && depth_lim == 0) break; cnt=0; calc(p,q,1,0,1); printf("%d\n", cnt); } return 0; }