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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Primorial numbers step by step in the 11l 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 11l programming language

Source code in the 11l programming language

F get_primes(primes_count)
   V limit = 17 * primes_count
   V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
   L(n) 0 .< Int(limit ^ 0.5 + 1.5)
      I is_prime[n]
         L(i) (n * n .< limit + 1).step(n)
            is_prime[i] = 0B

   [Int] primes
   L(prime) is_prime
      I prime
         primes.append(L.index)
         I primes.len == primes_count
            L.break
   R primes

V primes = get_primes(100000)

F primorial(n)
   BigInt r = 1
   L(i) 0 .< n
      r *= :primes[i]
   R r

print(‘First ten primorials: ’(0.<10).map(n -> primorial(n)))
L(e) 6
   V n = 10 ^ e
   print(‘primorial(#.) has #. digits’.format(n, String(primorial(n)).len))

  

You may also check:How to resolve the algorithm Remove duplicate elements step by step in the RPL programming language
You may also check:How to resolve the algorithm 24 game step by step in the PHP programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Binary search step by step in the Fortran programming language
You may also check:How to resolve the algorithm URL decoding step by step in the Wren programming language