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

Published on 12 May 2024 09:40 PM

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

Table of Contents

Problem Statement

Primorial numbers are those formed by multiplying successive prime numbers.

The primorial number series is: To express this mathematically,   primorialn   is   the product of the first   n   (successive) primes:

In some sense, generating primorial numbers is similar to factorials. As with factorials, primorial numbers get large quickly.

By   length   (above), it is meant the number of decimal digits in the numbers.

Let's start with the solution:

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

Source code in the picolisp programming language

(de prime? (N Lst)
   (let S (sqrt N)
      (for D Lst
         (T (> D S) T)
         (T (=0 (% N D)) NIL) ) ) )

(de take (N)
   (let I 1
      (make
         (link 2)
         (do (dec N)
            (until (prime? (inc 'I 2) (made)))
            (link I) ) ) ) )

# This is a simple approach to calculate primorial may not be the fastest one 
(de primorial (N)
   (apply * (take N)) )

#print 1st 10 primorial numbers
(for M 10 (prinl "primorial: "(primorial M)))

# print the length of primorial numbers.
[prinl (length (primorial (** 10 1)]
[prinl (length (primorial (** 10 2)]
[prinl (length (primorial (** 10 3)]
[prinl (length (primorial (** 10 4)]
#The last one takes a very long time to compute.
[prinl (length (primorial (** 10 5)]

  

You may also check:How to resolve the algorithm Leap year step by step in the Genie programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the Action! programming language
You may also check:How to resolve the algorithm Mayan numerals step by step in the Java programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the Julia programming language
You may also check:How to resolve the algorithm Digital root step by step in the jq programming language