Just carefully follow this solution and then you can quickly solve these type of questions without much worry.
LCM of 20 and 80 is 80
So let's assume the distance from A to B be 80 km.
Now time taken from A to B is 80/20 = 4 hrs.
Time taken from B to A is 80/80 = 1 hrs.
Total distance travelled = 80+80 = 160 km
Total time = 4+1 = 5 hrs.
Average speed = 160/5 =32 km/hr.
I hope it was simple enough.
Why did we take the distance equal to the LCM of 20 and 80?
Ans: We did it because that would make our calculations very easy as we are getting the time in integer values 4 & 1 and not any point value which would increase the calculation time.
u may assume distance as x.