Investments#11821

Investments (Editorial)

Author : Omar Aliyev

Solution Explanation

Sashko starts with an initial balance of hryvnias. Each year the bank adds interest, but the fractional part of the new balance is discarded. In other words, after each year the balance becomes:

B := B + \left\lfloor \frac{B}{100} \right\rfloor

We are given a target value , and we must determine the minimum number of years needed for the balance to reach at least .

Key Observation

The value increases slowly because each year the added amount is:

\left\lfloor \frac{B}{100} \right\rfloor

Since grows at most by per year, the number of years is on the order of a few thousand even for X = 10^9.

The process can be simulated year by year because:

Thus a direct loop is efficient.

Algorithm

Complexity

The loop runs approximately iterations for the largest input, so the time complexity is:

\mathcal{O}(X^{0}) = \mathcal{O}(1)

and memory usage is constant.

Reference Implementation

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long X;
    cin >> X;

    long long B = 100;
    long long years = 0;

    while (B < X) {
        long long inc = B / 100;  // integer division, drop fractions
        B += inc;
        years++;
    }

    cout << years << "\n";
    return 0;
}