The speed of the river is ...
.. (40 m/min)*(60 min/h)*((1 km)/(1000 m)) = 2.4 km/h
speed = distance/time
Let d represent the distance between the ports. Let s represent the speed of the ship.
Downstream, we have
.. s +2.4 = d/4.5
.. s = d/4.5 -2.4
Upstream, we have
.. s -2.4 = d/6/3
.. s = d/6.3 +2.4
Now, we have the speed of the ship represented two ways. We assume the speed of the ship doesn't vary. so these are equal.
.. (d/6.3) +2.4 = (d/4.5) -2.4
.. 4.8 = d(1/4.5 -1/6.3) = d(4/63) . . . . . rearrange and simplify
.. 75.6 = d . . . . . . . . . . . . . . . . . . . . . . .multiply by 63/4
The distance between the two ports is 75.6 km.