How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Delphi programming language

Table of Contents

Problem Statement

Consider the number 24. Its proper divisors are: 1, 2, 3, 4, 6, 8 and 12. Their product is 13,824 and the cube root of this is 24. So 24 satisfies the definition in the task title. Compute and show here the first 50 positive integers which are the cube roots of the product of their proper divisors. Also show the 500th and 5,000th such numbers. Compute and show the 50,000th such number. OEIS considers 1 to be the first number in this sequence even though, strictly speaking, it has no proper divisors. Please therefore do likewise.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Delphi programming language

Source code in the delphi programming language

function GetAllProperDivisors(N: Integer;var IA: TIntegerDynArray): integer;
{Make a list of all the "proper dividers" for N}
{Proper dividers are the of numbers the divide evenly into N}
var I: integer;
begin
SetLength(IA,0);
for I:=1 to N-1 do
 if (N mod I)=0 then
	begin
	SetLength(IA,Length(IA)+1);
	IA[High(IA)]:=I;
	end;
end;

function CubeTest(N: int64): boolean;
{Test is N^3 = product of proper dividers}
var IA: TIntegerDynArray;
var P: int64;
var I: integer;
begin
GetAllProperDivisors(N,IA);
P:=1;
for I:=0 to High(IA) do P:=P * IA[I];
Result:=P=(N*N*N);
end;


procedure ShowCubeEqualsProper(Memo: TMemo);
{Show set the of N^3 = product of proper dividers}
var I,Cnt: integer;
var S: string;
begin
{Show the first 50}
Cnt:=0;
for I:=1 to High(Integer) do
 if CubeTest(I) then
	begin
	Inc(Cnt);
	S:=S+Format('%8D',[I]);
	If (Cnt mod 5)=0 then S:=S+#$0D#$0A;
	if Cnt>=50 then break;
	end;
Memo.Lines.Add(S);
{Show 500th, 5,000th and 50,000th}
Cnt:=0;
for I:=1 to High(Integer) do
 if CubeTest(I) then
	begin
	Inc(Cnt);

	if Cnt=500 then Memo.Lines.Add('500th = '+IntToStr(I));
	if Cnt=5000 then Memo.Lines.Add('5,000th = '+IntToStr(I));
	if Cnt=50000 then
		begin
		Memo.Lines.Add('50,000th = '+IntToStr(I));
		break;
		end;
	end;
end;


  

You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the Delphi programming language
You may also check:How to resolve the algorithm Hickerson series of almost integers step by step in the C programming language
You may also check:How to resolve the algorithm Successive prime differences step by step in the zkl programming language
You may also check:How to resolve the algorithm Elliptic curve arithmetic step by step in the Python programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the JavaScript programming language