1455A - Strange Functions
30 Nov 2020 — Tags: math — URLObservations:
- $f(f(x))$ is the same as stripping $x$ from all it’s trailing zeros.
- $\frac{x}{f(f(x))}$ will always be the biggest power of $10$ that is a factor of $x$.
- 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;
}