80, because the horse rides to the front once and to the back once then he continues on foot.
An army begins marching in a single file, straight line that is 40 miles long. They march for 40 miles. In the time that it takes the army to march 40 miles, the soldier who is last in line rides a horse to the front of the line to deliver a message; then rides his horse back to his position at the back of the line. He returns to his position in line at the same time the army completes its 40th mile. How many total miles does the horse run?
A=back of army line (speed = a), B=horse position (speed = b)Code:A:@a....y.......40-y... B:@b................40+y...............
A travels distance y, to position 
B travels 40 miles further (to end of army line) to position 
A arrives at  at same time as B arrives at 
A continues such that it travels total of 40, to position 
B comes back, to position  : both get there at same time
You now have enough info to get b = a[1 + SQRT(2)]
From that, you can calculate y
Distance by horse = x + 2y
That's all I'll give you; don't wanna spoil your fun of getting b, then y
x = 40 ; from  :
(x + 2y) / b = x / a ; leads to x = 2ay / (b-a)
(x - y) / a = y / b ; leads to x = (ay + by) / b
2ay / (b-a) = (ay + by) / b
The y's cancel out and we get: b^2 - 2ab - a^2 = 0
Using quadratic: b = a +- aSQRT(2)
"-" impossible, so b = a[1 + SQRT(2)]
Substitute back and you should be ok.