How to print the first 25 abundant numbers in Java

1 Answer

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

public class MyClass {
    private static int SumNumberProperDivisors(final int num) {
    	int sum = 1;
    
    	for (int i = 2, j; i * i <= num; i++) {
    		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++) {
		    if (SumNumberProperDivisors(num) > num) {
			    System.out.println(++i + " " + num);
		    }
	    }
    }
}




/*
run:

1 12
2 18
3 20
4 24
5 30
6 36
7 40
8 42
9 48
10 54
11 56
12 60
13 66
14 70
15 72
16 78
17 80
18 84
19 88
20 90
21 96
22 100
23 102
24 104
25 108

*/


 



answered Oct 31, 2022 by avibootz

Related questions

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