It could be a multiple of the product of the two primes. For instance, if your two primes are 2 and 3, and you have 30 as the number, then you end up with a mod of 0.
However, a 5 has managed to creep into your number, which messes things up.
Modular math theory is covered in a subject called Abstact Algebra. If you're interested, you should try and find a book on it at a library somewhere.