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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Prime decomposition step by step in the EasyLang 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 EasyLang programming language

Source code in the easylang programming language

proc decompose num . primes[] .
   primes[] = [ ]
   t = 2
   while t * t <= num
      if num mod t = 0
         primes[] &= t
         num = num / t
      else
         t += 1
      .
   .
   primes[] &= num
.
decompose 9007199254740991 r[]
print r[]

  

You may also check:How to resolve the algorithm Create an HTML table step by step in the Batch File programming language
You may also check:How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the Visual Basic programming language
You may also check:How to resolve the algorithm Order two numerical lists step by step in the clojure programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Action! programming language
You may also check:How to resolve the algorithm Gaussian primes step by step in the Quackery programming language