How to resolve the algorithm Chowla numbers step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the Ada programming language
Table of Contents
Problem Statement
Chowla numbers are also known as:
The chowla number of n is (as defined by Chowla's function):
The sequence is named after Sarvadaman D. S. Chowla, (22 October 1907 ──► 10 December 1995), a London born Indian American mathematician specializing in number theory.
German mathematician Carl Friedrich Gauss (1777─1855) said:
Chowla numbers can also be expressed as:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chowla numbers step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_IO;
procedure Chowla_Numbers is
function Chowla (N : Positive) return Natural is
Sum : Natural := 0;
I : Positive := 2;
J : Positive;
begin
while I * I <= N loop
if N mod I = 0 then
J := N / I;
Sum := Sum + I + (if I = J then 0 else J);
end if;
I := I + 1;
end loop;
return Sum;
end Chowla;
procedure Put_37_First is
use Ada.Text_IO;
begin
for A in Positive range 1 .. 37 loop
Put_Line ("chowla(" & A'Image & ") = " & Chowla (A)'Image);
end loop;
end Put_37_First;
procedure Put_Prime is
use Ada.Text_IO;
Count : Natural := 0;
Power : Positive := 100;
begin
for N in Positive range 2 .. 10_000_000 loop
if Chowla (N) = 0 then
Count := Count + 1;
end if;
if N mod Power = 0 then
Put_Line ("There is " & Count'Image & " primes < " & Power'Image);
Power := Power * 10;
end if;
end loop;
end Put_Prime;
procedure Put_Perfect is
use Ada.Text_IO;
Count : Natural := 0;
Limit : constant := 350_000_000;
K : Natural := 2;
Kk : Natural := 3;
P : Natural;
begin
loop
P := K * Kk;
exit when P > Limit;
if Chowla (P) = P - 1 then
Put_Line (P'Image & " is a perfect number");
Count := Count + 1;
end if;
K := Kk + 1;
Kk := Kk + K;
end loop;
Put_Line ("There are " & Count'Image & " perfect numbers < " & Limit'Image);
end Put_Perfect;
begin
Put_37_First;
Put_Prime;
Put_Perfect;
end Chowla_Numbers;
You may also check:How to resolve the algorithm Polymorphism step by step in the Factor programming language
You may also check:How to resolve the algorithm Array length step by step in the Lingo programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Prolog programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the Ruby programming language
You may also check:How to resolve the algorithm Arrays step by step in the GML programming language