How to resolve the algorithm Chowla numbers step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the REXX 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 REXX programming language
Source code in the rexx programming language
/*REXX program computes/displays chowla numbers (and may count primes & perfect numbers.*/
parse arg LO HI . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
perf= LO<0; LO= abs(LO) /*Negative? Then determine if perfect.*/
if HI=='' | HI=="," then HI= LO /*Not specified? Then use the default.*/
prim= HI<0; HI= abs(HI) /*Negative? Then determine if a prime.*/
numeric digits max(9, length(HI) + 1 ) /*use enough decimal digits for // */
w= length( commas(HI) ) /*W: used in aligning output numbers.*/
tell= \(prim | perf) /*set boolean value for showing chowlas*/
p= 0 /*the number of primes found (so far).*/
do j=LO to HI; #= chowla(j) /*compute the cholwa number for J. */
if tell then say right('chowla('commas(j)")", w+9) ' = ' right( commas(#), w)
else if #==0 then if j>1 then p= p+1
if perf then if j-1==# & j>1 then say right(commas(j), w) ' is a perfect number.'
end /*j*/
if prim & \perf then say 'number of primes found for the range ' commas(LO) " to " ,
commas(HI) " (inclusive) is: " commas(p)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
chowla: procedure; parse arg x; if x<2 then return 0; odd= x // 2
s=0 /* [↓] use EVEN or ODD integers. ___*/
do k=2+odd by 1+odd while k*k
if x//k==0 then s=s + k + x%k /*add the two divisors to the sum. */
end /*k*/ /* [↓] adkust for square. ___*/
if k*k==x then s=s + k /*Was X a square? If so, add √ X */
return s /*return " " " " " */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do k=length(_)-3 to 1 by -3; _= insert(',', _, k); end; return _
You may also check:How to resolve the algorithm Accumulator factory step by step in the C programming language
You may also check:How to resolve the algorithm Guess the number step by step in the R programming language
You may also check:How to resolve the algorithm Extend your language step by step in the C# programming language
You may also check:How to resolve the algorithm OpenGL step by step in the Go programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Fōrmulæ programming language