How to print the first 25 abundant odd numbers 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[]) {
        for (int num = 1, i = 0; i < 25; num += 2) {
		    if (SumOddNumberProperDivisors(num) > num) {
			    System.out.println(++i + " " + num);
		    }
	    }
    }
}




/*
run:

1 945
2 1575
3 2205
4 2835
5 3465
6 4095
7 4725
8 5355
9 5775
10 5985
11 6435
12 6615
13 6825
14 7245
15 7425
16 7875
17 8085
18 8415
19 8505
20 8925
21 9135
22 9555
23 9765
24 10395
25 11025

*/


 



answered Oct 31, 2022 by avibootz

Related questions

1 answer 104 views
1 answer 89 views
1 answer 91 views
1 answer 81 views
2 answers 100 views
1 answer 95 views
...