Let the distance between points A and B be d.
When they meet for the first time, car M has traveled 500 while car N has traveled (d-500).
As time taken by both is the same to travel the respective distances , and calculating d as a multiple of 100 to simplify
=> Speed of M/ Speed of N = 5/(d-5)
The next time they meet car M has traveled (d-500)+ 300, while car N has traveled 500 + d-300
=> Speed of M/ Speed of N = (d-2)/ (d+2)
Equating them both we get => 5(d+2)= (d-5)(d-2) => d=12
Thus distance between the two points in 1200.
Speed of M/Speed of N = 5/(12-5)= 5/7