How to resolve the algorithm Semiprime step by step in the EchoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Semiprime step by step in the EchoLisp programming language
Table of Contents
Problem Statement
Semiprime numbers are natural numbers that are products of exactly two (possibly equal) prime numbers.
Semiprimes are also known as:
(This particular number was chosen as the length of the Arecibo message).
Write a function determining whether a given number is semiprime.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Semiprime step by step in the EchoLisp programming language
Source code in the echolisp programming language
(lib 'math)
(define (semi-prime? n)
(= (length (prime-factors n)) 2))
(for ((i 100))
(when (semi-prime? i) (write i)))
4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95
(lib 'bigint)
(define N (* (random-prime 10000000) (random-prime 10000000)))
→ 6764578882969
(semi-prime? N)
→ #t
;; a pair n,n+1 of semi-primes
(prime-factors 100000000041)
→ (3 33333333347)
(prime-factors 100000000042)
→ (2 50000000021)
You may also check:How to resolve the algorithm Eban numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the MiniScript programming language
You may also check:How to resolve the algorithm HTTP step by step in the Ring programming language
You may also check:How to resolve the algorithm CSV data manipulation step by step in the Forth programming language