While if does accept vectors for the condition, using vectors often causes problems like this. When the if condition is a vector then all of its elements must be true for the if to execute the code inside the if. In the first usage you were lucky:
this works because for prime numbers all of them a remainder zero. But in your other usages, e.g.
it will not be the case that all of the elements of that condition vector would be true, therefore those if never execute the code inside them.
The if help explains it thus: "An expression is true when its result is nonempty and contains only nonzero elements...": is this the case when you are trying to detect the b and c values? No, it is not, because some of the elements will be false.
The solution is simple: always write an explicit all or any when using a vector with if, because it makes the intention clear, and avoids bugs like this (and it will fix your bug, when pick the correct one). I would recommend that you do not use two nested if's: just use one if with a logical &&: