DEV Community

Discussion on: Write a script to find "Perfect Numbers"

Collapse
 
stefanrendevski profile image
Stefan Rendevski

You can reduce it even further by using "while (i <= sqrt(n))" and noticing that divisors come in pairs, for example: if 16 / 2 = 8, both 2 and 8 are divisors of 16. There is no need to go up to 8 and check all integers up until that point, you only need to perform the division.