How to print the one thousandth abundant odd number in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

// abundant odd number = sum of proper divisors > number

unsigned SumOddNumberProperDivisors(const unsigned num) {
    unsigned sum = 1;

    for (unsigned i = 3, j; i < sqrt(num) + 1; i += 2)
        if (num % i == 0)
            sum += i + (i == (j = num / i) ? 0 : j);

    return sum;
}

int main()
{
    unsigned num = 1;

    for (unsigned i = 0; i < 1000; num += 2) {
        if (SumOddNumberProperDivisors(num) > num) {
            i++;
        }
    }

    printf("%u", num);

    return 0;
}




/*
run:

492977

*/

 



answered Oct 22, 2022 by avibootz
edited Oct 22, 2022 by avibootz

Related questions

1 answer 113 views
1 answer 107 views
1 answer 109 views
...