Suppose that the numbers are r,s,t,u,v, where one of these is a second is b and so on, p = rstuv.

Increase r by 1 and you have (r+1)stuv = rstuv + stuv, so n - p = (r+1)stuv - rstuv = stuv.

n - p will take its greatest value when stuv takes its greatest value and that will be when s,t,u and v are the four greatest numbers (and r is the smallest).