  The observed lifetimes of gaseous protoplanetary discs place strong
constraints on gas and ice giant formation in the core accretion scenario. The
approximately 10-Earth-mass solid core responsible for the attraction of the
gaseous envelope has to form before gas dissipation in the protoplanetary disc
is completed within 1-10 million years. Building up the core by collisions
between km-sized planetesimals fails to meet this time-scale constraint,
especially at wide stellar separations. Nonetheless, gas-giant planets are
detected by direct imaging at wide orbital distances. In this paper, we
numerically study the growth of cores by the accretion of cm-sized pebbles
loosely coupled to the gas. We measure the accretion rate onto seed masses
ranging from a large planetesimal to a fully grown 10-Earth-mass core and test
different particle sizes. The numerical results are in good agreement with our
analytic expressions, indicating the existence of two accretion regimes, one
set by the azimuthal and radial particle drift for the lower seed masses and
the other, for higher masses, by the velocity at the edge of the Hill sphere.
In the former, the optimally accreted particle size increases with core mass,
while in the latter the optimal size is centimeters, independent of core mass.
We discuss the implications for rapid core growth of gas-giant and ice-giant
cores. We conclude that pebble accretion can resolve the long-standing core
accretion time-scale conflict. This requires a near-unity dust-to-gas ratio in
the midplane, particle growth to mm and cm and the formation of massive
planetesimals or low radial pressure support. The core growth time-scale is
shortened by a factor 30-1,000 at 5 AU and by a factor 100-10,000 at 50 AU,
compared to the gravitationally focused accretion of, respectively,
low-scale-height planetesimal fragments or standard km-sized planetesimals.
