Erdős-Nicolas numbers: Difference between revisions

Line 460:
=={{header|Java}}==
<syntaxhighlight>
import java.util.Arrays;
 
public final class ErdosNicolasNumbers {
 
public static void main(String[] aArgs) {
final int limit = 100_000_000;
int[] divisorSum = new int[limit + 1];
int[] divisorCount = new int[limit + 1];
Arrays.fill(divisorSum, 1);
Arrays.fill(divisorCount, 1);
for ( int index = 2; index <= limit / 2; ++index ) {
for ( int number = 2 * index; number <= limit; number += index ) {
if ( divisorSum[number] == number ) {
System.out.println(String.format("%8d", number) + " equals the sum of its first "
+ String.format("%3d", divisorCount[number]) + " divisors");
}
divisorSum[number] += index;
++divisorCount[number];
}
}
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
24 equals the sum of its first 6 divisors
 
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
61900800 equals the sum of its first 280 divisors
91963648 equals the sum of its first 142 divisors
</pre>
 
891

edits