How to resolve the algorithm Factorial primes step by step in the Phix programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factorial primes step by step in the Phix programming language

Table of Contents

Problem Statement

A factorial prime is a prime number that is one less or one more than a factorial. In other words a non-negative integer n corresponds to a factorial prime if either n! - 1 or n! + 1 is prime.
4 corresponds to the factorial prime 4! - 1 = 23. 5 doesn't correspond to a factorial prime because neither 5! - 1 = 119 (7 x 17) nor 5! + 1 = 121 (11 x 11) are prime. Find and show here the first 10 factorial primes. As well as the prime itself show the factorial number n to which it corresponds and whether 1 is to be added or subtracted. As 0! (by convention) and 1! are both 1, ignore the former and start counting from 1!. If your language supports arbitrary sized integers, do the same for at least the next 19 factorial primes. As it can take a long time to demonstrate that a large number (above say 2^64) is definitely prime, you may instead use a function which shows that a number is probably prime to a reasonable degree of certainty. Most 'big integer' libraries have such a function. If a number has more than 40 digits, do not show the full number. Show instead the first 20 and the last 20 digits and how many digits in total the number has.

Let's start with the solution: