Let's first find the portion of work that each person can do in a day:
A can do 1/20 of the work in a day.
B can do 1/30 of the work in a day.
C can do 1/40 of the work in a day.
Working together, the three of them can do:
1/20 + 1/30 + 1/40 = 6/120 = 1/20
So, they can complete 1/20 of the work in a day.
Let's say the total work is represented by the variable W. Since they worked together for x days, the portion of work completed by the three of them is (1/20)xW.
After 5 days, A left, so only B and C were working for x-5 days. The portion of work completed by B and C is (1/30 + 1/40)(x-5)W.
After another 5 days, B also left, so only C was working for x-10 days. The portion of work completed by C is (1/40)(x-10)W.
The total portion of work completed is the sum of these three portions:
(1/20)xW + (1/30 + 1/40)(x-5)W + (1/40)(x-10)W = W
Simplifying this equation, we get:
x/4 - 1/8 = 1
Multiplying both sides by 8, we get:
2x - 1 = 8
2x = 9
x = 4.5
Therefore, the three of them working together can complete the work in 4.5 days.