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

Published on 12 May 2024 09:40 PM

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

Table of Contents

Problem Statement

Write a function which says whether a number is perfect.

A perfect number is a positive integer that is the sum of its proper positive divisors excluding the number itself. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).

Note:   The faster   Lucas-Lehmer test   is used to find primes of the form   2n-1,   all known perfect numbers can be derived from these primes using the formula   (2n - 1) × 2n - 1. It is not known if there are any odd perfect numbers (any that exist are larger than 102000). The number of   known   perfect numbers is   51   (as of December, 2018),   and the largest known perfect number contains  49,724,095  decimal digits.

Let's start with the solution:

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

Source code in the picolisp programming language

(de perfect (N)
   (let C 0
      (for I (/ N 2)
         (and (=0 (% N I)) (inc 'C I)) )
      (= C N) ) )

(de faster (N)
   (let (C 1  Stop (sqrt N))
      (for (I 2 (<= I Stop) (inc I))
         (and
            (=0 (% N I))
            (inc 'C (+ (/ N I) I)) ) )
      (= C N) ) )

  

You may also check:How to resolve the algorithm Higher-order functions step by step in the Ol programming language
You may also check:How to resolve the algorithm Fairshare between two and more step by step in the REXX programming language
You may also check:How to resolve the algorithm Exponentiation operator step by step in the ZX Spectrum Basic programming language
You may also check:How to resolve the algorithm Minkowski question-mark function step by step in the Raku programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Red programming language