Chowla numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
m (added highlighting to the task's preamble.)
m (used a more consistent spacing in the task's preamble.)
Line 35: Line 35:
chowla(<big>'''n'''</big>) = sigma(<big>'''n'''</big>) <big>'''-1 - n''' </big>
chowla(<big>'''n'''</big>) = sigma(<big>'''n'''</big>) <big>'''-1 - n''' </big>
chowla(<big>'''n'''</big>) = sigmaProperDivisiors(<big>'''n'''</big>) <big>'''-1''' </big>
chowla(<big>'''n'''</big>) = sigmaProperDivisiors(<big>'''n'''</big>) <big>'''-1''' </big>
chowla(<big>'''a'''*'''b'''</big>) = <big>'''a''' + '''b'''</big>, &nbsp; &nbsp; ''if'' &nbsp; <big>'''a'''</big> &nbsp; and &nbsp; <big>'''b'''</big> &nbsp; are distinct primes
chowla(<big>'''a'''*'''b'''</big>) = <big>'''a''' + '''b'''</big>, &nbsp; ''if'' <big>'''a'''</big> and <big>'''b'''</big> are distinct primes
if chowla(<big>'''n'''</big>) = <big>'''0'''</big>, and <big>'''n > 1'''</big>, then <big>'''n'''</big> is prime
if chowla(<big>'''n'''</big>) = <big>'''0'''</big>, and <big>'''n > 1'''</big>, then <big>'''n'''</big> is prime
if chowla(<big>'''n'''</big>) = <big>'''n - 1'''</big>, and <big>'''n > 1'''</big>, then <big>'''n'''</big> is a perfect number
if chowla(<big>'''n'''</big>) = <big>'''n - 1'''</big>, and <big>'''n > 1'''</big>, then <big>'''n'''</big> is a perfect number



Revision as of 07:46, 11 March 2019

Chowla numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Chowla numbers are also known as:

  •   Chowla's function
  •   the chowla function
  •   the chowla number
  •   the chowla sequence



The chowla number of   n   is   (as defined by Chowla's function):

  •   the sum of the divisors of   n     excluding unity and   n
  •   where   n   is a positive integer


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,   "Mathematics is the queen of the sciences ─ and number theory is the queen of mathematics".


Definitions

Chowla numbers can also be expressed as:

   chowla(n) = sum of divisors of  n  excluding unity and  n
   chowla(n) = sum(       divisors(n))   -1  -  n 
   chowla(n) = sum( properDivisors(n))   -1       
   chowla(n) = sum(aliquotDivisors(n))   -1        
   chowla(n) = aliquot(n)                -1       
   chowla(n) = sigma(n)                  -1  -  n 
   chowla(n) = sigmaProperDivisiors(n)   -1       
   chowla(a*b) = a + b,    if  a  and  b  are distinct primes
   if  chowla(n) =  0,  and  n > 1,  then   n   is prime
   if  chowla(n) =  n - 1,  and n > 1,  then   n   is a perfect number


Task
  •   create a   chowla   function that returns the   chowla number   for a positive integer   n
  •   Find and display   (1 per line)   for the 1st   37   integers:
  •   the integer   (the index)
  •   the chowla number for that integer
  •   For finding primes, use the   chowla   function to find values of zero
  •   Find and display the   count   of the primes up to              100
  •   Find and display the   count   of the primes up to           1,000
  •   Find and display the   count   of the primes up to         10,000
  •   Find and display the   count   of the primes up to       100,000
  •   Find and display the   count   of the primes up to    1,000,000
  •   Find and display the   count   of the primes up to  10,000,000
  •   For finding perfect numbers, use the   chowla   function to find values of   n - 1
  •   Find and display all   perfect numbers   up to   35,000,000
  •   use commas within appropriate numbers
  •   show all output here



Related tasks


See also



REXX

<lang rexx>/*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<x    /*divide by all the integers up to √ X */
           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 _</lang>

output   when using the input of:     1     37
  chowla(1)  =   0
  chowla(2)  =   0
  chowla(3)  =   0
  chowla(4)  =   2
  chowla(5)  =   0
  chowla(6)  =   5
  chowla(7)  =   0
  chowla(8)  =   6
  chowla(9)  =   3
 chowla(10)  =   7
 chowla(11)  =   0
 chowla(12)  =  15
 chowla(13)  =   0
 chowla(14)  =   9
 chowla(15)  =   8
 chowla(16)  =  14
 chowla(17)  =   0
 chowla(18)  =  20
 chowla(19)  =   0
 chowla(20)  =  21
 chowla(21)  =  10
 chowla(22)  =  13
 chowla(23)  =   0
 chowla(24)  =  35
 chowla(25)  =   5
 chowla(26)  =  15
 chowla(27)  =  12
 chowla(28)  =  27
 chowla(29)  =   0
 chowla(30)  =  41
 chowla(31)  =   0
 chowla(32)  =  30
 chowla(33)  =  14
 chowla(34)  =  19
 chowla(35)  =  12
 chowla(36)  =  54
 chowla(37)  =   0
output   when using the input of:     1     -100
number of primes found for the range  1  to  100  (inclusive)  is:  25
output   when using the input of:     1     -1,000
number of primes found for the range  1  to  1,000  (inclusive)  is:  168
output   when using the input of:     1     -10,000
number of primes found for the range  1  to  10,000  (inclusive)  is:  1,229
output   when using the input of:     1     -100,000
number of primes found for the range  1  to  100,000  (inclusive)  is:  9,592
output   when using the input of:     1     -1,000,000
number of primes found for the range  1  to  1,000,000  (inclusive)  is:  78.498
output   when using the input of:     1     -10,000,000
number of primes found for the range  1  to  10,000,000  (inclusive)  is:  664,579
output   when using the input of:     -1     35,000,000
         6  is a perfect number.
        28  is a perfect number.
       496  is a perfect number.
     8,128  is a perfect number.
33,550,336  is a perfect number.