How to resolve the algorithm Chowla numbers step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the XPL0 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 XPL0 programming language
Source code in the xpl0 programming language
func Chowla(N); \Return sum of divisors
int N, Div, Sum, Quot;
[Div:= 2; Sum:= 0;
loop [Quot:= N/Div;
if Quot < Div then quit;
if Quot = Div and rem(0) = 0 then \N is a square
[Sum:= Sum+Quot; quit];
if rem(0) = 0 then
Sum:= Sum + Div + Quot;
Div:= Div+1;
];
return Sum;
];
int N, C, P;
[for N:= 1 to 37 do
[IntOut(0, N); Text(0, ": ");
IntOut(0, Chowla(N)); CrLf(0);
];
C:= 1; \count 2 as prime
N:= 3; \only check odd numbers
repeat if Chowla(N) = 0 then \N is prime
C:= C+1;
case N+1 of 100, 1000, 10_000, 100_000, 1_000_000, 10_000_000:
[Text(0, "There are "); IntOut(0, C); Text(0, " primes < ");
IntOut(0, N+1); CrLf(0)]
other [];
N:= N+2;
until N >= 10_000_000;
P:= 1; \perfect numbers are of form: 2^(P-1) * (2^P - 1)
loop [P:= P*2;
N:= P*(P*2-1);
if N > 35_000_000 then quit;
if Chowla(N) = N-1 then \N is perfect
[IntOut(0, N); CrLf(0)];
];
]
You may also check:How to resolve the algorithm Stirling numbers of the first kind step by step in the Raku programming language
You may also check:How to resolve the algorithm Knuth's algorithm S step by step in the Python programming language
You may also check:How to resolve the algorithm HTTPS/Client-authenticated step by step in the zkl programming language
You may also check:How to resolve the algorithm Closures/Value capture step by step in the Groovy programming language
You may also check:How to resolve the algorithm Rep-string step by step in the PL/I programming language