Optimiztion Assistance

Help with optimization is needed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int Divisors(int);
int main(){
	int d=0,i=1,n=0;
	while(d<=500){
		n+=i++;
		d=Divisors(n);
	}
	cout << n << endl;
	return 0;
}
int Divisors(int n){
	int d=0;
	for(int i=1;i<=n;i++){
		if(n%i==0)d++;
	}
	return d;
}


if anyone has any ideas on how to optimize, let me know.

p.s. im willing to rewrite the entire app if someone has a better layout
Last edited on
What is your task? Finding the lowest number with over 500 factors? While little things could be optimised (line 16 could have i*i<=n condition, since all factors (except for the root) come in pairs), I think there may be a simple way to assemble such number.
Google "sum factors." Click the first link. Implement, solve.
thanks guys, my orignal program finished running, but i will take a look at the sum factors equation, even though it is slightly different than what im looking for (number of factors vs sum of factors)
My mistake. Should've looked more closely.

http://mathforum.org/library/drmath/view/55843.html is more relevant.
Topic archived. No new replies allowed.