Finding the number that gives remainder equal to 0

1.6k Views Asked by At

Hi i'm not english so I'll try to explain this as good as I can .

If we have for example

250 : 5 = 50 , remainder 0

let's say I don't know the number i'm going to divide (because it is generated random or it changes) , but I know that I want a reimander of the division equal to 0

so N : X = A , with R = 0

I need a formula or a way to find the X that gives to me R = 0

1

There are 1 best solutions below

1
On BEST ANSWER

You want to find a divisor for an arbitrary integer, that's how it's normally called.

If you allow X to be N or 1, then you are OK. If you don't allow that, you might find some cases where it's not possible, those are called "prime numbers"; for example there is no integer except 1 and 13 that divide 13 with remainder 0.

An easy algorithm is to test all the odd numbers from 3 to the square root of N. Checking for divisibility is very quick, you don't need to perform the division, just additions and multiplications.