How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Ada programming language
Table of Contents
Problem Statement
Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Show here, on this page, at least the first 15 terms of the sequence.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_IO;
procedure Show_Sequence is
function Count_Divisors (N : in Natural) return Natural is
Count : Natural := 0;
I : Natural;
begin
I := 1;
while I**2 <= N loop
if N mod I = 0 then
if I = N / I then
Count := Count + 1;
else
Count := Count + 2;
end if;
end if;
I := I + 1;
end loop;
return Count;
end Count_Divisors;
procedure Show (Max : in Natural) is
use Ada.Text_IO;
N : Natural := 1;
Begin
Put_Line ("The first" & Max'Image & "terms of the sequence are:");
for Divisors in 1 .. Max loop
while Count_Divisors (N) /= Divisors loop
N := N + 1;
end loop;
Put (N'Image);
end loop;
New_Line;
end Show;
begin
Show (15);
end Show_Sequence;
You may also check:How to resolve the algorithm Knuth shuffle step by step in the Maxima programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the OCaml programming language
You may also check:How to resolve the algorithm Poker hand analyser step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Department numbers step by step in the F# programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the Julia programming language