Otherwise, you have a counting loop with a non-trivial condition. This is one of those things that's always annoying to expressionexpress in Python. In C/C++ or C++, that'd be:
Otherwise, you have a counting loop with a non-trivial condition. This is one of those things that's always annoying to expression in Python. In C/C++, that'd be:
Otherwise, you have a counting loop with a non-trivial condition. This is one of those things that's always annoying to express in Python. In C or C++, that'd be:
Nope, running time is O(sqrt(N))
\$ O(\sqrt N) \$ worst-case. Consider the case of a prime number (or particularly bad cases, like the product of twin primes). You have to check sqrt(N)
\$ \sqrt N \$ possible values to find the answer. No way around that.
Nope, running time is O(sqrt(N))
worst-case. Consider the case of a prime number (or particularly bad cases, like the product of twin primes). You have to check sqrt(N)
possible values to find the answer. No way around that.
Nope, running time is \$ O(\sqrt N) \$ worst-case. Consider the case of a prime number (or particularly bad cases, like the product of twin primes). You have to check \$ \sqrt N \$ possible values to find the answer. No way around that.
That's about as good as you're going to get with this approach. If you want better performance, you'd have to get a different algorithm. In this answer this answer, I show an approach with Pollard's rho, which would give a dramatic performance improvement just by doing something completely different:
That's about as good as you're going to get with this approach. If you want better performance, you'd have to get a different algorithm. In this answer, I show an approach with Pollard's rho, which would give a dramatic performance improvement just by doing something completely different:
That's about as good as you're going to get with this approach. If you want better performance, you'd have to get a different algorithm. In this answer, I show an approach with Pollard's rho, which would give a dramatic performance improvement just by doing something completely different: