Check if an integer has any prime factors excluding some set

113 Views Asked by At

I'm looking for an algorithm that returns true if the set of prime factors of some number only contains values in some set $S$, and false otherwise

Example:

$S = \{2,5\}$

For the number $250$ the result is true, since the prime divisors are $2*5^3$
For the number $182$ the result is false, since the prime divisors are $2*7*13$

Since I don't need the actual divisors, I'm hoping there's a faster method than just factoring the number.