Problems > Compound Doubling > Editorial

Compound Doubling — Solution & Editorial

Back to the Problem

Simulate year by year with integer flooring: b += b·R/100. B ≥ 100 guarantees the yearly gain is at least 1, and the loop runs at most ~70 iterations (R = 1 doubles in about 70 years).

Complexity: O(1) or O(log)

Watch out: Floating-point interest drifts off the integer flooring — keep the whole simulation in integers.