to check the divisibility of an integer (say A) by another integer(say B) , i have tried an approach by factoring B and checking if A is divisible by all the prime factors of B . However i’m not sure if its correct ? Could you please suggest what can be done ? For e.g if we have a very large integer say 10^100 and we want to check if its divisible by another integer say 200 then i was trying if 10^100 is divisible by 2 and 5 (by noticing the last digit).
If A is small enough we could directly have checked if A%B==0 but i was trying this for larger numbers.
Thanks,
to check the divisibility of an integer (say A) by another integer(say B) ,
Share
You have to count the number of times that the prime appears in the factorization of
B, and ensure that it appears at least as many times in the factorization ofA.So, 200 = 23 * 52. Then
Ais divisible by 200 if and only if it is divisible by 23 and by 52.Unless you somehow know the factorization already, factorizing
Ais far slower than just dividing it byB. The reason is that it will take many trial divisions (or equivalent work) to fully factorizeA, whereas it only takes one trial division to check it for divisibility byB. After all, consider the case whereBis prime: you’ve found all prime factors ofA, when all you needed was to test whether or notBis one of them. This cannot possibly be less work.