Description
For given fourpositive integers p, q, a, and n, count the number of partitions ofp/q into unit fractions satisfying the following twoconditions.
The partition is thesum of at most n many unitfractions.
The product of thedenominators of the unit fractions in the partition is less than orequal to a.
For example, if(p,q,a,n) = (2,3,120,3), you should report 4since
enumerates all of thevalid partitions.
Input
A data set is a linecontaining four positive integers p, q, a, and n satisfying p,q<= 800, a <= 12000 and n<= 7. The integers are separated by aspace.
The terminator iscomposed of just one line which contains four zeros separated by aspace. It is not a part of the input data but a mark for the end ofthe input.
Output
The output integercorresponding to a data set p, q, a, n should be the number of allpartitions of p/q into at most n many unit fractions such that theproduct of the denominators of the unit fractions is less than orequal to a.
SampleInput
2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 3 300 1
2 1 200 5
2 4 54 2
0 0 0 0
SampleOutput
4
7
6
2
42
1
0
9
3
Source
#include
using
int
int
int
}
void
}
void
}
int
}