I used similar approach as Sudhir here. Just to add some more explanation ...
Question is asking to us find out the least amount of time that Machine B needs to work. We know that the maximum working time is 8 hours ... so if Machine A worked for for its maximum time: 8 hours, then it would have produced 9000*8 = 72000 pencils.
This leaves 28000 pencils to be produced (100000-72000).
From this we can work out how long machine B needs to work.