Biggest and lowest number below N that you can get multiplying two number of K and and L digits

180 Views Asked by At

What is the biggest number below or equal to N that you can get by multiply two other number of K and L digits?

According to this post [a post from Quora], if you have two number of K and L digit, the product of this two number will have (K+L) or (K+L-1) digit.

So, if for example I have N=75148 (5 digits), what are the lowest and biggest number below 75148 that I can get by multiplying two numbers for example of 2 digit and 3 digit?

And so in general, my question is: given a whole number N, and given two other whole number K and L, what are the biggest and lowest whole number below or equal to N that you can get by multiplying a number of K digits with a number of L digits?

Input: N, K, L  

Output 1: T,p,q 
where T=p*q  
and p is a number of K digits 
and q is a number of L digits 
and T <= N
and T is the biggest possible number such that T <= N

Output 2: U,f,g
where U=f*g
and f is a number of K digits
and g is a number of L digits
and U <= N
and U is the smallest possible number such that U <= N

All of this are whole numbers

1

There are 1 best solutions below

1
On

The smallest number you can get multiplying $2$ digits by $3$ digits is $10 \cdot 100=1000$

To get the largest number less than $75148$ all I can think of is to count downward and check. We can factor $75147=3\cdot 37 \cdot 677$ and observe that there is not way to split up the factors to get $2$ times $3$ digits. $75146=2\cdot 37573$ doesn't work, either, but $75145=5\cdot 7 \cdot 19 \cdot 113=95 \cdot 791$ does and we are done.

What you need is to have the two digit number larger than the leading two digits of the product, so you want the largest number less than $75148$ that has a factor in the range $[76,99]$. If there aren't any greater than or equal to $75000$ you can expand the factor range to $[75,99]$ This would suggest an algorithm. Loop downward from the starting number, then loop over the large two digit numbers and check divisibility.