For weight and balance purposes, you find the moment around a given point created by a given object by multiplying the distance between the given point and the object and the mass of the object.
Similarly, the moment about that same given point created by the aircraft as a whole is given by the distance between the center of gravity and that given point multiplied by the total mass of the aircraft.
If the given point is the CoG datum, the distance between the center of gravity and the given point is the figure you are looking for when doing your weight and balance calculations.
Hence, if you calculate the moments created by all the objects you wish to include about the CoG datum and sum them up, the summed moments will equal the moment created by the entire aircraft around the CoG datum.
You can also easily calculate the mass of the aircraft as a whole by summing up the mass of all the objects you wish to include.
Now, let's put this in algebra.
The moment M is the product of the CoG distance d and the mass of the entire aircraft m.
M = d * m
The CoG distance d is what we are looking for. Rearranging the above by dividing both sides by the total mass m we get
M/m = d * m / m
Or, as m/m is equal to one
d = M / m * 1 = M / m
That's your division, right there.
The moment M1 created by object 1, say, the unfuelled aircraft, is similarly given as the product of the distance from the CoG datum to the object d1 and the mass of the object m1.
M1 = d1 * m1
Similarly, for object 2 (e g the fuel added)
M2 = d2 * m2
Now, by the above the moment created by the fuel AND the unfuelled aircraft will be the same as the moment created by the entire aircraft.
M1 + M2 = M
The total mass is m1 added to m2.
m = m1 + m2
Now, go back to
d = M / m
insert M = M1 + M2 and m = m1 + m2
d = (M1 + M2) / (m1 + m2)
The CoG distance is the sum of the moments divided by the sum of the masses.