#B3629. Minimum Number of Popsicles to Buy
Minimum Number of Popsicles to Buy
Minimum Number of Popsicles to Buy
Doraemon loves to eat popsicles. When he buys a popsicle and eats it, he is left with a stick. For every three sticks he collects, he can exchange them for one new popsicle. Note that the exchanged popsicle, once eaten, also gives a stick.
For example, if Doraemon buys 5 popsicles, he will have 5 sticks. He can exchange 3 sticks for 1 popsicle (with 2 sticks remaining). After eating the exchanged popsicle, he gains 1 additional stick, making a total of 3 sticks again. He exchanges these 3 sticks for another popsicle. In total, Doraemon eats 7 popsicles.
Given an integer \(n\), representing the total number of popsicles Doraemon wants to eat, determine the minimum number of popsicles he must initially buy.
Note: All formulas in this problem should be represented in \(\LaTeX\) format.
In mathematical notation, let \(X\) be the number of popsicles purchased. Doraemon obtains one stick per popsicle and for every exchange of 3 sticks he gets another popsicle (and one additional stick after consumption). We are asked to find the smallest \(X\) such that the total number of popsicles eaten is at least \(n\).
inputFormat
The input consists of a single integer \(n\) \((1 \leq n \leq 10^9)\), representing the number of popsicles Doraemon wants to eat.
outputFormat
Print a single integer, the minimum number of popsicles Doraemon must initially buy so that he can eat at least \(n\) popsicles.
sample
7
5
</p>