A loop goes thru all numbers from one to N to find perfect numbers. For each number in the range, it checks all numbers less than it to see if it's a divisor by modding it by the number and checking if the result is zero. It keeps track of the running total of the divisors, and stops if the running total gets higher than the number being checked. What's the complexity of this? I think it's something exponential...Here's the C++ code I wrote to do it:
for(int i = 0; i < nums_to_check.size(); i++) { number = nums_to_check[i]; running_total = 0; for(unsigned long long j = number-1; j > 0; j--) { if(number % j == 0) { running_total += j; if(running_total > number) break; } } if(running_total == number) perfect_numbers.push_back(number); }