Abundant numbers

I have a function to tell if a number is abundant, as defined by Project Euler Problem 23, but my function is saying that all numbers are abundant. I'm thinking that it's a problem with my for loop, but I'm not sure where.

1
2
3
4
5
6
7
8
9
bool abundant(int num)
{
	//declare variables
	int sum = 0;

	for(int x = 1; x * x <= num; sum += num % x ? 0 : (x * x == num ? x : x + num / x), x++);

	return sum > num;
}//end abundant 
Last edited on
Your code is obfuscated.
It fails because you are considering the number as a divisor.
I found the problem now. Thank you.
Topic archived. No new replies allowed.