If X
can have at most n
digits and Y
can have at most m
digits, then
X < 10 ^ n and Y < 10 ^ m
This means that
X * Y < 10 ^ n * 10 ^ m = 10 ^ (n + m)
In other words,
X * Y can have at most n + m digits.
With division, we need to take the worst case for Y
- that is value 1. So maximum number of digits for X / Y
is n
.
However, if you know Y has exactly m digits, then we can say that
Y >= 10 ^ (m - 1)
in that case we get:
X / Y < (10 ^ n) / (10 ^ (m-1)) => X / Y < (10 ^ (n - m + 1))
This means that X / Y
has at most n - m + 1
digits when Y has exactly m digits.