Number of digits after multiplication, dividing

一世执手 提交于 2021-01-29 07:18:16

问题


I have two numbers X and Y, i don't know their values but i know that the maximal number of digits that can contain X is 10 (for example) and for Y is 3 (for example)

I need to know the maximal number of digits of Z that equals to X * Y. Same for Z = X / Y


回答1:


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.




回答2:


assume the number of digit in X is n and for Y is m and values are rounded so

the maximum number of digits in (x*y) is n+m and

the maximum number of digits in (x/y) is n-m+1



来源:https://stackoverflow.com/questions/24303813/number-of-digits-after-multiplication-dividing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!