How to resolve the algorithm Fortunate numbers step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fortunate numbers step by step in the Arturo programming language

Table of Contents

Problem Statement

A Fortunate number is the smallest integer m > 1 such that for a given positive integer n, primorial(n) + m is a prime number, where primorial(n) is the product of the first n prime numbers. For example the first fortunate number is 3 because primorial(1) is 2 and 2 + 3 = 5 which is prime whereas 2 + 2 = 4 is composite.

After sorting and removal of any duplicates, compute and show on this page the first 8 Fortunate numbers or, if your language supports big integers, the first 50 Fortunate numbers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Fortunate numbers step by step in the Arturo programming language

Source code in the arturo programming language

firstPrimes: select 1..100 => prime?
primorial: function [n][
    product first.n: n firstPrimes
]

fortunates: []
i: 1

while [8 > size fortunates][
    m: 3
    pmi: primorial i
    while -> not? prime? m + pmi
          -> m: m+2
    fortunates: unique fortunates ++ m
    i: i + 1
]

print sort fortunates


  

You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Ranking methods step by step in the Elixir programming language