Let's say the man threw $x$ flowers into the lake. Then he has $3x$ flowers and puts $y$ of them into the first temple, leaving him with $3x-y$ flowers.
He throws them in again, resulting in $9x - 3y$ flowers, and puts $y$ of them in the temple again, for $9x - 4y$ flowers.
He throws them in a third time resulting in $27x - 12y$ flowers, and puts $y$ of them in the temple, for $27x - 13y = 0$ flowers.
The smallest integer solution that will work here is
$x = 13$, $y = 27$, so the man had 13 flowers initially and put 27 flowers in each temple.
In general, this sort of problem is called an annuity problem, and has applications in finances when calculating amortization rates of mortgages (hence the term "annuity problem"). In the above example, an equivalent problem using loans would be that you have a debt of \$13 with an annual interest rate of 200% that you want to pay off in 3 years, which requires a payment of \$27 every year. To calculate the payments required, the following formula is used:
$$p = \frac{P(1+i)^n}{1 + (1+i) + (1+i)^2 + (1+i)^3 + \ldots + (1+i)^{n-1}} = \frac{P(1+i)^n i}{(1+i)^n - 1}$$
where $p$ is the periodic payment, $P$ is the initial principal amount, $n$ is the number of pay periods, and $i$ is the interest rate per pay period. In the problem statement above, $i = 2$ and $n = 3$, so the ratio of flowers put into each temple to initial flowers is 27/13 ($p = \frac{P(2+1)^3(2)}{(2+1)^3 - 1} = \frac{54P}{26} = \frac{27}{13}P$), which is consistent with what working it out manually gave us.
You'll notice with the above formula that any multiple of 13 flowers would work, if you put the same multiple of 27 flowers into each temple. If you allowed for fractional flowers, you could start with 1 flower and put 27/13 flowers into each temple and it would work out the same way.