We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Scott • 4 years ago

> for i in range(2, int(n**0.5+1.5)):

As written, this code just tries all the integers (composite or not) up through sqrt(n). It's worth the extra lookup to only try the prime divisors:

> for i in range(2, int(n**0.5+1.5)):
> if prime[i]: