1455A - Strange Functions

Observations:

  1. $f(f(x))$ is the same as stripping $x$ from all it’s trailing zeros.
  2. $\frac{x}{f(f(x))}$ will always be the biggest power of $10$ that is a factor of $x$.
  3. Finding all unique values of the formula is the same as finding all possible powers of ten less or equal than $x$.

Time complexity: $O(1)$

Memory complexity: $O(1)$

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        cout << (int)(s).size() << endl;
    }
    return 0;
}