According to the formula for gravity between two objects, the earth and moon will gravitationally attract one another no matter how far apart they are, so what we're looking for is the work to separate them infinitely far. That is, we want to calculate
∫a∞F(r)dr, where a=400000000 m.
If we take m1 and m2 to be the mass of the earth and moon as given in the question statement, then:
Gm1m2=(6.7×10−11 kg⋅sec2m3)(6×1024 kg)(7×1022 kg)≈2.8×1037 sec2kg⋅m3
With that out of the way, let's calculate our work.
W=∫a∞F(r)dr=b→∞lim∫abGr2m1m2dr=(Gm1m2)b→∞lim[−r1]ab=(Gm1m2)b→∞lim(a1−b1)=aGm1m2≈4×108 m2.8×1037 sec2kg⋅m3=7×1028 J
Remark: since the force of gravity between the earth and the moon gets weaker as they are farther apart, it takes less and less work to move them each kilometre. If we move them a finite distance apart, the work involved will always be less than 7×1028 joules, no matter how huge that finite distance is. If we move them a very, very long (but finite) distance apart, the work we did will be quite close to (but still less than) 7×1028 joules.