Hello,
you only have to use Pythagorean theorem:
With your problem the hypotenuse is (r+R). You'll get:
$\displaystyle (AP)^2 + R^2 = (r+R)^2$
$\displaystyle (AP)^2 = (r+R)^2-R^2$
$\displaystyle (AP)^2 = r^2 + 2rR +R^2-R^2$
$\displaystyle (AP)^2 = r^2 + 2rR $
$\displaystyle |AP| = \sqrt{r^2 + 2rR }$