Find if x is divisible by a number in the sequence from 2 to p

98 Views Asked by At

What's the best way ( in terms of complexity ) to find if $x$ is divisible by any number between $2..p$ ( inclusive), the obvious solution is to iterate over all numbers $i$ between $2$ and $p$ and check if $x\%i==0$, that's work in $O(p)$.

My solution is to find all divisor of $x$ in $O(\sqrt{x})$ and check if one of these divisors is between $2$ and $p$, is there a faster approach?