Language: C++

#include <cmath>
#include <cstdio>
#pragma warning(disable : 4996)
using namespace std;
template<typename Type> Type gcd(Type a, Type b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
// ----- Fraction Class ------ //
template<class Type> class Fraction {
public:
	// ------ Variable ------ //
	Type p, q;
	// ------ Constructor ------ //
	Fraction() : p(0), q(1) {}
	Fraction(const Type& p_, const Type& q_) : p(p_ / gcd(abs<Type>(p_), abs<Type>(q_))), q(q_ / gcd(abs<Type>(p_), abs<Type>(q_))) { if (q < 0) p = -p, q = -q; }
	Fraction(const Fraction<Type>& f) : p(f.p), q(f.q) {}
	// ------ Operator ------ //
	template<class Type2> friend bool operator==(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return f1 == f2; }
	template<class Type2> friend bool operator!=(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return f1 != f2; }
	template<class Type2> friend Fraction operator+(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return Fraction(f1.p * f2.q + f1.q * f2.p, f1.q * f2.q); }
	template<class Type2> friend Fraction operator-(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return Fraction(f1.p * f2.q - f1.q * f2.p, f1.q * f2.q); }
	template<class Type2> friend Fraction operator*(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return Fraction(f1.p * f2.p, f1.q * f2.q); }
	template<class Type2> friend Fraction operator/(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { return Fraction(f1.p * f2.q, f1.q * f2.p); }
	template<class Type2> friend bool operator<(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { Fraction f3 = f1 - f2; return f3.p < 0; }
	template<class Type2> friend bool operator>(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { Fraction f3 = f1 - f2; return f3.p > 0; }
	template<class Type2> friend bool operator<=(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { Fraction f3 = f1 - f2; return f3.p <= 0; }
	template<class Type2> friend bool operator>=(const Fraction<Type2>& f1, const Fraction<Type2>& f2) { Fraction f3 = f1 - f2; return f3.p >= 0; }
	template<class Type2> Fraction& operator+=(const Fraction<Type2>& f1) { Fraction f2 = Fraction(p * f1.q + q * f1.p, q * f1.q); p = f2.p; q = f2.q; return *this; }
	template<class Type2> Fraction& operator-=(const Fraction<Type2>& f1) { Fraction f2 = Fraction(p * f1.q - q * f1.p, q * f1.q); p = f2.p; q = f2.q; return *this; }
	template<class Type2> Fraction& operator*=(const Fraction<Type2>& f1) { Fraction f2 = Fraction(p * f1.p, q * f1.q); p = f2.p; q = f2.q; return *this; }
	template<class Type2> Fraction& operator/=(const Fraction<Type2>& f1) { Fraction f2 = Fraction(p * f1.q, q * f1.p); p = f2.p; q = f2.q; return *this; }
};
Fraction<int> f; int p, q, a, n;
int solve(Fraction<int> f1, int a1, int c, int d) {
	if (f1 > f) return 0;
	if (f1 == f) return 1;
	if (d >= n) return 0;
	int ret = 0;
	for (int i = c; a1 * i <= a; i++) {
		ret += solve(f1 + Fraction<int>(1, i), a1 * i, i, d + 1);
	}
	return ret;
}
int main() {
	while (~scanf("%d%d%d%d", &p, &q, &a, &n)) {
		if (p == 0 && q == 0 && a == 0 && n == 0) break;
		f = Fraction<int>(p, q);
		printf("%d\n", solve(Fraction<int>(0, 1), 1, 1, 0));
	}
	return 0;
}

Compiler output:
a.cc: In constructor 'Fraction<Type>::Fraction(const Type&, const Type&)':
a.cc:16:71: error: expected primary-expression before '>' token
   16 |         Fraction(const Type& p_, const Type& q_) : p(p_ / gcd(abs<Type>(p_), abs<Type>(q_))), q(q_ / gcd(abs<Type>(p_), abs<Type>(q_))) { if (q < 0) p = -p, q = -q; }
      |                                                                       ^
a.cc:16:86: error: expected primary-expression before '>' token
   16 |         Fraction(const Type& p_, const Type& q_) : p(p_ / gcd(abs<Type>(p_), abs<Type>(q_))), q(q_ / gcd(abs<Type>(p_), abs<Type>(q_))) { if (q < 0) p = -p, q = -q; }
      |                                                                                      ^
a.cc:16:114: error: expected primary-expression before '>' token
   16 |         Fraction(const Type& p_, const Type& q_) : p(p_ / gcd(abs<Type>(p_), abs<Type>(q_))), q(q_ / gcd(abs<Type>(p_), abs<Type>(q_))) { if (q < 0) p = -p, q = -q; }
      |                                                                                                                  ^
a.cc:16:129: error: expected primary-expression before '>' token
   16 |         Fraction(const Type& p_, const Type& q_) : p(p_ / gcd(abs<Type>(p_), abs<Type>(q_))), q(q_ / gcd(abs<Type>(p_), abs<Type>(q_))) { if (q < 0) p = -p, q = -q; }
      |                                                                                                                                 ^