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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Perfect numbers step by step in the ERRE 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 ERRE programming language

Source code in the erre programming language

PROGRAM PERFECT

PROCEDURE PERFECT(N%->OK%)
      LOCAL I%,S%
      S%=1
      FOR I%=2 TO SQR(N%)-1 DO
        IF N% MOD I%=0 THEN S%+=I%+N% DIV I%
      END FOR
      IF I%=SQR(N%) THEN S%+=I%
      OK%=(N%=S%)
END PROCEDURE

BEGIN
    PRINT(CHR$(12);) ! CLS
    FOR N%=2 TO 10000 STEP 2 DO
       PERFECT(N%->OK%)
       IF OK% THEN PRINT(N%)
    END FOR
END PROGRAM

  

You may also check:How to resolve the algorithm Empty program step by step in the Brainf*** programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the Python programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Swift programming language
You may also check:How to resolve the algorithm Multisplit step by step in the Swift programming language
You may also check:How to resolve the algorithm Almost prime step by step in the PHP programming language