How to maximize returns in this scenario You have a machine. You can put money into it. You have $s$ initial budget. $p$ percent of the time the machine will double your investment. $(100-p)$ percent of the time it will just swallow your money and not return anything. You can choose a ratio $a$ of your money to reinvest at every turn into the machine. E.g. if $a=1$, then you are reinvesting all your money at every turn (and very quickly will be left with nothing).
What is the optimal ratio $a$ with which your money grows the fastest with respect to the number of times you put money in the machine?

Let $p' = p/100$ denote the probability of winning at a turn with the machine.  Your initial capital is $W_0 = s$.  After the first turn where you bet $aW_0$, your wealth is
$$W_1 = W_0 + aW_0X_1 = W_0(1 +aX_1),$$
where $X_1$ is a binary random variable such that $P(X_1 = 1) = p'$ and $P(X_1 = -1) = 1-p'$.  
Assume that the outcome of a turn depends in no way on the outcomes of previous turns. After $n$ turns, your wealth is
$$W_n = W_0(1 +aX_1)(1+aX_2) \cdots(1+aX_n)$$
where $X_1, X_2, \ldots, X_n$ are independent and identically distributed binary random variables.
The compounded rate-of-growth is
$$R_n(a) = \log \left[\left(\frac{W_n}{W_0} \right)^{1/n}\right] = \frac{1}{n} \log \left(\frac{W_n}{W_0} \right)= \frac{1}{n}\sum_{k=1}^n\log(1+aX_k),$$
with the expected value
$$G_n(a) = E[R_n(a)] = \frac{1}{n}\sum_{k=1}^n E[ \log(1+aX_k)].$$
Since the random variables are identically distributed, we have for all $k$, 
$$E[ \log(1+aX_k)]  = E[ \log(1+aX_1)] = p'\log(1+a) + (1-p')\log(1-a), $$
and, hence, the expected rate-of-growth is independent of $n$:
$$G_n(a) = \frac{1}{n} \sum_{k = 1}^n [p'\log(1+a) + (1-p')\log(1-a)] = p'\log(1+a) + (1-p')\log(1-a)  $$
If the odds are in your favor we have $p' > 1/2$ and setting the derivative of $G_n$ equal to $0$ determines the optimal proportion $a^*$ that maximizes the rate-of-growth, that is
$$G_n'(a^*) = \frac{p'}{1+a^*} - \frac{1-p'}{1 - a^*} = 0 \\ \implies a^* = 2p'-1$$
This is commonly known as the Kelly criterion.
If the odds are not in your favor we have $p' \leqslant 1/2$ and there is no strategy that produce a positive expected rate-of-growth -- see  Gambler's ruin. We can only establish another objective like maximizing the probability of doubling initial capital and quitting. At even odds, $p'= 1/2$, it is best to bet everything on one turn.
