How to find the number of solutions in a diaphragus equation with 3 unknown, when given a, b, c, d.
Time limit: 0.1C
Memory limit: 64MIB
Monk Charles Great
Karl the Great, really great, as he thought about the future of the inhabitants of his country. In one of the first famous schools of the city of Aachen, he invited in 795 to teach the mathematics of the monk Alkuin, who offered such a task:
100 of the postfelle (monetary units) were divided between men, women and children and gave men to 3 Sheffel, women on 2 and children on Paul Sheffel. How many men, women and children were? “
The general solution of linear diophantine equations in those days have not yet known and were content with only a few solutions that satisfy the condition of the problem. Alcois himself contained only one solution to this problem: men, women and children were 11, 15 and 74, and the task in fact has 784 solutions in natural numbers.
We offer you to go on on the way of absorption of diophantine equations and solve such a task in the following form: “With the insane, the women were divided between men, women and children. Men were given by Schifplel, women – for B Schifelfel, and children, like in Ancient times, half of the chaffles. “
How many solutions in natural numbers have this task?
In the only row, three natural numbers are given: a, b and c. All input data does not exceed 1000.
Display the only number – the answer of the problem.
3 2 100.
Here I tried stupidly bust but it is not clear why it does not work.
a, b, c = map (int, input (). Split ()) # c = a * x + b * y + 0.5 * z Count = 0. For x in Range (1, C + 1): For y in Range (1, C + 1): For z in Range (1, C + 1): IF a * x + b * y + 0.5 * z == C: Count + = 1 PRINT (COUNT)
Answer 1, Authority 100%
To work, you need to correctly set the z
for x in range (1, c // a +1): For y in Range (1, c // B +1): For z in Range (1, 2 * C + 1):
and it is worth working in integers (here it takes and without it, with other coefficients you can pierce)
if 2 * a * x + 2 * b * y + z == 2 * C:
With a larger range it is worth thinking about a more efficient method