At first understand the fact that friend should make their moves one be one and the friend who initially was left should move to the right and other friend should move to the left. Let len = |a - b|. Then the first friend will make cntA = len / 2 moves, and the second friend — cntB = len - len / 2 moves. So the answer is the sum of two arithmetic progressions cntA·(cntA + 1) / 2 and cntB·(cntB + 1) / 2.
The given constrains allowed to calculate this sums in linear time — simply iterate from 1 to cntA for the first sum and from 1 to cntB to the second.
Thanks GreenGrape for translation!