# How to find the nearest integer number that when multiplied by a set of decimals still gives an integer number?

I do not know how to properly formulate this question, but I am trying to find the best algorithm to get the nearest integer number where every set of numbers (including decimals) give an integer number when doing multiplication. Example:

Assuming:

``````X = 232
Y = [2, 5, 1, 0.1, 0.0625]
``````

The final number will depend on both 0.1 and 0.0625 (given that integer multiplication will always be another integer):

``````232 * 0.1 = 23.2

232 * 0.0625 = 14.5
``````
• 232 can't be, both results still have decimal.

Now we can assume using 230 will work for 0.1, but:

``````230 * 0.1 = it works, it is a proper integer.
230 * 0.0625 = 14.375 but not really because it still has a decimal when multiplied by 0.0625.
``````

The number that actually works is 160 (every number ending with 0 will suit 0.1, but not 0.0625):

``````160 * 0.1 = 16
160 * 0.0625 = 10
``````
• 160 suits both perfectly, so this is the number we were looking for (notice we began with 232 and went all the way back to find the nearest integer that suits every number in Y).

What will be the correct algorithm to determine this faster and efficiently independently of how many numbers with decimals I may have?

• "Nearest" to what? Or do you mean "smallest" (= nearest to zero)? "Independently of how many numbers with decimals" makes obviously no sense, since for processing N numbers, the minimum processing time cannot be less than O(N). Please edit the question and clarify. – Doc Brown Oct 8 '20 at 10:16