How to print the one thousandth abundant odd number in Java

1 Answer

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

public class MyClass {
    private static int SumOddNumberProperDivisors(final int num) {
    	int sum = 1;
    
    	for (int i = 3, j; i < Math.sqrt(num) + 1; i += 2) {
    		if (num % i == 0) {
    			sum += i + (i == (j = num / i) ? 0 : j);
    		}
    	}
    
    	return sum;
    }
    public static void main(String args[]) {
        int num = 1;

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

	    System.out.print(num);
    }
}





/*
run:

492977

*/

 



answered Oct 31, 2022 by avibootz

Related questions

1 answer 97 views
1 answer 87 views
1 answer 92 views
...