#t47. 百鸡问题扩展
百鸡问题扩展
Generalized Hundred-Chickens Problem
Problem Description
The "Hundred Chickens" problem is a famous mathematical puzzle from the ancient Chinese book Zhang Qiujian Suanjing. In brief:
"Each rooster costs yuan, each hen costs yuan, and chicks cost yuan; now with yuan you buy chickens — how many schemes are there?"
Xiao Ming loves this story and decides to generalize it and solve it by programming: if each rooster costs yuan, each hen costs yuan, and every chicks cost yuan; and now with yuan you buy chickens, how many schemes are there?
Input Format
The input gives one line containing five integers: , , , , from the problem description. It is given that and .
Output Format
Output one line containing a single integer , the number of schemes.
Sample Input 1
5 3 3 100 100
Sample Output 1
4
Sample Input 2
1 1 1 100 100
Sample Output 2
5151
Sample Explanation
The first sample corresponds to the classic "Hundred Chickens" problem: each rooster yuan, each hen yuan, every chicks yuan, yuan total, buying chickens. There are schemes:
- roosters, hens, chicks: cost $0 \times 5 + 25 \times 3 + 75 \div 3 = 0 + 75 + 25 = 100$ yuan, total chickens.
- roosters, hens, chicks: cost $4 \times 5 + 18 \times 3 + 78 \div 3 = 20 + 54 + 26 = 100$ yuan, total chickens.
- roosters, hens, chicks: cost $8 \times 5 + 11 \times 3 + 81 \div 3 = 40 + 33 + 27 = 100$ yuan, total chickens.
- roosters, hens, chicks: cost $12 \times 5 + 4 \times 3 + 84 \div 3 = 60 + 12 + 28 = 100$ yuan, total chickens.
Therefore the output is .
Constraints
, .