Then according to "one person has to work for 40 hours", one person's working speed is 1/40.
The key to this problem is that adding two people complicates the problem. You simplify, two people do 8 hours, and the others do 4+8 hours.
The work done by two people in eight hours is very clear. What they did was done by an unknown number of people. Their time is 4=8= 12 hours. Divide the workload by the working hours and the number of people will come out.
The two additional people worked for 8 hours and completed 2*8* 1/40=2/5.
The unknown part is 1-2/5=3/5.
Unknown people do 4 hours +8 hours = 12 hours,
So there are (4/5)/( 12* 1/40)=2 people in this part.