#include using namespace std; int gcd( int m, int n ) { return ( n == 0 )? m : gcd(n, m%n); } int P, Q, A, N; void recursive( int nterm, int denomLbound, int num, int denom, int denomProduct, int &result ) { if ( nterm == N ) return; for ( int d = denomLbound; d <= A; d++ ) { if ( denomProduct * d > A ) break; const int newDenomProduct = denomProduct * d; const int GCD = gcd(denom, d); const int newDenom = denom*(d/GCD); const int newNum = num*(d/GCD) + (denom/GCD); const int numUpperBound = num*(d/GCD) + (N-nterm)*(denom/GCD); if ( P*newDenom > Q*numUpperBound ) break; if ( P*newDenom == Q*newNum ) result++; else if ( P*newDenom < Q*newNum ) continue; else recursive(nterm+1, d, newNum, newDenom, newDenomProduct, result); } } int main() { while ( true ) { cin >> P >> Q >> A >> N; if ( P == 0 && Q == 0 && A == 0 && N == 0 ) break; int result = 0; recursive(0, 1, 0, 1, 1, result); cout << result << endl; } return 0; }