How to resolve the algorithm Erdős-Nicolas numbers step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Erdős-Nicolas numbers step by step in the Delphi programming language

Table of Contents

Problem Statement

An Erdős–Nicolas number is a positive integer which is not perfect but is equal to the sum of its first k divisors (arranged in ascending order and including one) for some value of k greater than one. 24 is an Erdős–Nicolas number because the sum of its first 6 divisors (1, 2, 3, 4, 6 and 8) is equal to 24 and it is not perfect because 12 is also a divisor. 6 is not an Erdős–Nicolas number because it is perfect (1 + 2 + 3 = 6). 48 is not an Erdős–Nicolas number because its divisors are: 1, 2, 3, 4, 6, 8, 12, 16, 24 and 48. The first seven of these add up to 36, but the first eight add up to 52 which is more than 48. Find and show here the first 8 Erdős–Nicolas numbers and the number of divisors needed (i.e. the value of 'k') to satisfy the definition. Do the same for any further Erdős–Nicolas numbers which you have the patience for. As all known Erdős–Nicolas numbers are even you may assume this to be generally true in order to quicken up the search. However, it is not obvious (to me at least) why this should necessarily be the case.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Erdős-Nicolas numbers step by step in the Delphi programming language

Source code in the delphi programming language

const MaxNumber = 100000000;
var DSum: array [0..MaxNumber-1] of integer;
var DCount: array [0..MaxNumber-1] of integer;

procedure ShowErdosNicolasNumbers(Memo: TMemo);
var I,J: integer;
begin
for I:=0 to MaxNumber-1 do
	begin
	DSum[I]:=1;
	DCount[I]:=1;
	end;
for I:=2 to MaxNumber-1 do
	begin
	J:=I*2;
	while J
		begin
		if dsum[J] = j then
			begin
			Memo.Lines.Add(Format('%8d equals the sum of its first %d divisors', [j, dcount[j]]));
			end;
		Inc(dsum[J],I);
		Inc(DCount[J]);
		Inc(J,I);
		end;
        end;
end;


  

You may also check:How to resolve the algorithm Dijkstra's algorithm step by step in the PHP programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the Tcl programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the Haskell programming language
You may also check:How to resolve the algorithm Runtime evaluation/In an environment step by step in the Scala programming language
You may also check:How to resolve the algorithm Stern-Brocot sequence step by step in the AutoHotkey programming language