Let number of rams be x, pigs be y and oxen be z
x+y+z=40 .......(i)
4x+2y+17z=301
Using x from (i), we have
4(40−y−z)+2y+17z=301
⇒160−4y−4z+2y+17z=301
⇒13z−2y=141 ..........(ii)
We will approach the question by finding the positive integral solutions of the equations as the number of animals can olny be some positive integer.
13z2−y=1412
⇒6z+z2−y=70+12
⇒6z−y+z−12=70
As y and z are integers
⇒z−12= integer
Let the integer be p
z−12=p
⇒z=2p+1 ..........(iii)
Substituting z in (ii)
13(2p+1)−2y=141
⇒2y=26p−128
⇒y=13p−64 .........(iv)
Substituting y and z in (i)
x+13p−64+2p+1=40
⇒x=103−15p ........(v)
We can see from (iv) that y<0 for integer p<5 and from (v) x<0 for integer p>6 , which is not possible as x and y can only be positive integers.
So, p can take values 5,6
Substituting p in (iii),(iv) and (v) , we get
⎧⎨⎩z=11,13y=1,14x=28,13
So, he can buy 28 rams, 1 pig and 11 oxen or 13 rams, 14 pig and 13 oxen.