for 2D a uniform-grid-partition can be handy. random google result : http://gameprogrammingpatterns.com/spatial-partition.html
the idea is very simple :
- divide space into cells.
- store objects inside cells.
-- to find the cell in which to store you can test a point, like the object center (easy)
-- or you can test which cells overlap with the object. (bit more complex)
- once stored - "select" or "query" objects from cell-partition with a geometric shape, in your case a circle.
this works as long as you do not group up too many objects in on cell. worst case is - all objects are in the same cell, what renders the cell-partitioning useless.
now, gravity itself is not going to well with that idea. eventually everything collapses into a singular point. this works better with "negative gravity", things that seperate, like water.
if you still want to do a "all-pairs" simulation (test every object with every other object) you could use a quad-tree and store the mass and center of mass for each quadrant/children and use this information to approximate the simulation. this is just a coarse description. read more here : http://en.wikipedia.org/wiki/Barnes%E2%80%93Hut_simulation
this is not as easy as cell-partition anymore tho'.