How to resolve the algorithm Prime decomposition step by step in the EchoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Prime decomposition step by step in the EchoLisp programming language

Table of Contents

Problem Statement

The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number.

Write a function which returns an array or collection which contains the prime decomposition of a given number

n

{\displaystyle n}

greater than   1. If your language does not have an isPrime-like function available, you may assume that you have a function which determines whether a number is prime (note its name before your code). If you would like to test code from this task, you may use code from trial division or the Sieve of Eratosthenes. Note: The program must not be limited by the word size of your computer or some other artificial limit; it should work for any number regardless of size (ignoring the physical limits of RAM etc).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Prime decomposition step by step in the EchoLisp programming language

Source code in the echolisp programming language

(prime-factors 1024)
   → (2 2 2 2 2 2 2 2 2 2)

(lib 'bigint)
;; 2^59 - 1
(prime-factors (1- (expt 2 59)))
    → (179951 3203431780337)

(prime-factors 100000000000000000037)
    → (31 821 66590107 59004541)


  

You may also check:How to resolve the algorithm Lucky and even lucky numbers step by step in the Ring programming language
You may also check:How to resolve the algorithm Discordian date step by step in the Nim programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Erlang programming language
You may also check:How to resolve the algorithm Anonymous recursion step by step in the Erlang programming language
You may also check:How to resolve the algorithm Superellipse step by step in the Wren programming language