Force of gravity acting between any two bodies is inversely proportional to the square of the distance between the two bodies. The distance between the two bodies as applicable for this relationship refers to the distance between the center of gravities of the two bodies.
In case of spheres with their mass distributed equally over the whole volume of the sphere the center of gravity lies at the center of the sphere. The distance between the centers of spheres of 10 km and 20 km radius, touching each other is equal to the sum of their radius. This comes to 30 km. Therefor the distance between these spheres, applicable for calculating force of gravity between them will also be 30 km.
The equation for the force of gravitational attraction is given by the expression G*M1*M2*/R^2, where M1 and M2 are the mass of the bodies, R is the distance between their centers of mass and G is the universal gravitational constant.
In the case of the spheres with radius 10 km and 20 km, which are touching each other, we would have to take the distance between them as 30 km to calculate the force of gravitational attraction. [It has been assumed here that the mass is uniformly distributed within the spheres.]