Project Euler Problem 12

I'm trying to finish this problem, but I run into the problem that I get an answer, but it's incorrect for some reason. Can anyone clue me in to where my problem is?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	//declare variables
	long long tri = 0;
	int div = 0;

	for(long x = 0; div <= 500; x++)
	{
		div = 0;
		long root = sqrt(double(tri));

		for(long a = 1; a <= root; a++)
		{
			if(tri % a == 0)
			{
				if(tri / a == a)
					div += 1;
				else
					div += 2;
			}//end if
		}//end for
		
		tri += x;
	}//end while

	cout << tri << endl;

return 0;
}//end main 
Check your for loop...is that right?
div <= 500
Yeah, that's right. I need to make sure that I the number has more than 500 divisors, so I test divisor at the end of each loop to make sure that there are more than 500 of them. Just figured out the problem anyways. Thanks for your help.
Topic archived. No new replies allowed.