Premium problem108. Succeeding Within r Retries

Easy Locked

An API call succeeds with probability p per attempt, and you will make at most r attempts. Return the probability it succeeds at some point.

P=1−(1−p)rP = 1 - (1-p)^r

A call that fails 20% of the time is down to 0.8% failure after three tries, which is why retries are worth so much more than they look.

Input

p = 0.8
r = 3

Output

0.992

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)