Robson » Code » C++ » Abundant

 
// abundant checker v1.0
 
// returns true if the number is abundant
// abundant numbers are lower than the sum of their proper divisors
bool is_abundant(int i)
{
    int divisors = 0;
    for (int n = 2; n * n <= i; n++)
    {
        if (!(i % n))
        {
           divisors += n;
           if (n < i / n)
              divisors += i / n;
           if (i <= divisors)
              return true;
        }
    }
    return i <= divisors;
}
 
© 2004-17 robson | cc unless stated