Erdős-Nicolas numbers: Difference between revisions

Content added Content deleted
(Added Perl)
(Added C++ solution)
Line 77: Line 77:
61900800 equals the sum of its first 280 divisors
61900800 equals the sum of its first 280 divisors
91963648 equals the sum of its first 142 divisors
91963648 equals the sum of its first 142 divisors
</pre>

=={{header|C++}}==
{{trans|ALGOL 68}}
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <vector>

int main() {
const int max_number = 100000000;
std::vector<int> dsum(max_number + 1, 1);
std::vector<int> dcount(max_number + 1, 1);
for (int i = 2; i <= max_number; ++i) {
for (int j = i + i; j <= max_number; j += i) {
if (dsum[j] == j) {
std::cout << std::setw(8) << j
<< " equals the sum of its first " << dcount[j]
<< " divisors\n";
}
dsum[j] += i;
++dcount[j];
}
}
}</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>
</pre>