Have you come across a question which is similar to the following:
A boy goes to a supermarket and buys some pencils and erasers . The cost of each pencil is $0.3 and cost of each eraser is $0.5. In how many ways could he have bought the pencils and erasers if he paid a total sum of $4.20 and bought at least one pencil and at least one eraser?
I am sure, most of you will be able to come up with the following equation: 0.3p + 0.5e = 4.2 and then, by multiplying both sides by 10, you will get:
3p + 5e = 42
(p - the number of pencils, e - the number of erasers)
What next? This is the equation of a line and has infinite solutions i.e. for every value of p, exists a value of e.
e.g. When p = 0, e = 42/5; when p = 0.1, e = (41.7)/5; when p = 1, e = 39/5 and so on…
Then, should I say he can buy the pencils and erasers in infinite ways e.g. 0 pencils and 42/5 erasers or 0.1 pencils and 41.7/5 erasers or 1 pencil and 39/5 erasers etc?
No! There is a catch! (but of course!)
Can I buy 42/5 = 8.4 erasers? I can buy 8 erasers or 9 erasers but how can I buy 8.4 erasers? So what we are looking for is integral values of p and e. This is one of the constraints on our solution and will narrow down the acceptable values.
Let us write the equation again: 3p + 5e = 42
One set of integral solution to this equation is p = 14, e = 0 (I will discuss later how I got to this.)
When you put p = 14 and e = 0 above, you get 3*14 + 5*0 = 42. Here, 3p = 42 and 5e = 0 and they add up to give 42. What if I want to get 42 in another way? I can decrease 3p by some amount and will have to increase 5e by the same amount to get the same sum of 42. E.g. I decrease 3p by 1 and increase 5e by 1 to get 41 + 1 = 42. So p was 14 and 3p was 42, but now I want 3p to be 41. What should p be? p = 41/3 - but this is not an integral value! We are looking for only integral solutions. Then let’s try to decrease p instead of 3p to ensure that we get integral values of p. If p = 13 instead of 14, I get 3p = 39. I decreased 3p by 3 .
Now, I must increase 5e by 3 to get the same sum of 42. 5e was 0, and needs to be 3 now. What will e be now? e = 3/5. Unfortunately, the problem is still the same. We need integral values of p and e. I can increase 5e is blocks of 5 only i.e. if e = 0, 5e = 0; e = 1, 5e = 5; e = 2, 5e = 10 etc.
Now the problem is that 3p can be decreased only in blocks of 3 and 5e can be increased only in blocks of 5. But the decrease in 3p has to be offset by the increase in 5e! Therefore, we should decrease/increase them in blocks of 15 (lowest common multiple of 3 and 5). So when I try to decrease 3p by 15, p decreases by 5 (the second term, 5e, has 5 as the co-efficient) and when I try to increase 5e by 15, e increases by 3 (the co-efficient of the first term). The table given below will make it clearer.
and so on…
Note that in second, third and fourth rows, we have been decreasing 3p and increasing 5e. We could do the opposite as done in the last two rows of the table above. We could increase p by 5 and decrease e by 3 to get more solutions. Once we have one solution, we can figure out infinite solutions. Then is our answer still infinite? Why the hell did we do all this work then!
Actually, there is another constraint. Can the number of pencils or erasers be negative? Also, since he buys at least one pencil and at least one eraser, p and e cannot be 0 .(First solution discarded) Then, a solution is one where values of p and e are positive integers.
Go back to the table. After the third row of solutions, if you keep decreasing 3p, p will be negative every time. Look at the last row - if you keep decreasing 5e, e will remain negative. Therefore, there are only two solutions (p = 9, e = 3) and (p = 4, e = 6). He could have bought pencils and erasers in only two ways.
Now we come back to ‘How do you get the first solution’. Simple – by brute force. Here it is easy since 42 is a multiple of 3. Then we know that p can be 14 to give 42 and 5e can be 0.
An equation such as 3p + 5e = 49 is trickier.
First, I check for e = 1. Reduce 49 by 5 to get 44 and then check – is 44 divisible by 3? – No.
Then check for e = 2. Reduce 44 by 5 again to get 39 – is 39 divisible by 3? – Yes!
This means 3p can be 39 and 5e can be 10 giving us p = 13 and e = 2. This would be our first solution and would lead us to more, possibly. How many positive integral solutions will this equation have?
Things to ponder upon:
- What can you say if your equation is of the form 3x + 6y = 40?
- Should coefficients of x and y be co-prime?
- And, a trickier thing to think about - how many integral solutions would 3x - 5y = 42 have?
(If you like, I would be happy to confirm your answers!)