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?
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
//declare variables
longlong 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
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.