How to resolve the algorithm Abundant odd numbers step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Abundant odd numbers step by step in the PicoLisp programming language

Table of Contents

Problem Statement

An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n.

12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of   1,2,3,4,6 & 12   which sum to   28   ( > 24 or 2n).

Abundant numbers are common, though even abundant numbers seem to be much more common than odd abundant numbers. To make things more interesting, this task is specifically about finding   odd abundant numbers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Abundant odd numbers step by step in the PicoLisp programming language

Source code in the picolisp programming language

(de accud (Var Key)
   (if (assoc Key (val Var))
      (con @ (inc (cdr @)))
      (push Var (cons Key 1)) )
   Key )
(de **sum (L)                                                                   
   (let S 1                                                                     
      (for I (cdr L)                                                            
         (inc 'S (** (car L) I)) )                                              
      S ) )        
(de factor-sum (N)
   (if (=1 N)
      0
      (let
         (R NIL
            D 2
            L (1 2 2 . (4 2 4 2 4 6 2 6 .))
            M (sqrt N)
            N1 N
            S 1 )
         (while (>= M D)
            (if (=0 (% N1 D))
               (setq M
                  (sqrt (setq N1 (/ N1 (accud 'R D)))) )
               (inc 'D (pop 'L)) ) )
         (accud 'R N1)
         (for I R
            (setq S (* S (**sum I))) )
         (- S N) ) ) )
(de factor-list NIL
   (let (N 1  C 0)
      (make
         (loop
            (when (> (setq @@ (factor-sum N)) N)
               (link (cons N @@))
               (inc 'C) )
            (inc 'N 2)
            (T (= C 1000)) ) ) ) )
(let L (factor-list)
   (for N 25
      (println N (++ L)) ) 
   (println 1000 (last L))
   (println 
      '****
      1000000575
      (factor-sum 1000000575) ) )

  

You may also check:How to resolve the algorithm ABC problem step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the MontiLang programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Order programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Dc programming language
You may also check:How to resolve the algorithm QR decomposition step by step in the F# programming language