How to resolve the algorithm Wilson primes of order n step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Wilson primes of order n step by step in the F# programming language

Table of Contents

Problem Statement

A Wilson prime of order n is a prime number   p   such that   p2   exactly divides:

If   n   is   1,   the latter formula reduces to the more familiar:   (p - n)! + 1   where the only known examples for   p   are   5,   13,   and   563.

Calculate and show on this page the Wilson primes, if any, for orders n = 1 to 11 inclusive and for primes p < 18   or, if your language supports big integers, for p < 11,000.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Wilson primes of order n step by step in the F# programming language

Source code in the fsharp programming language

// Wilson primes. Nigel Galloway: July 31st., 2021
let rec fN g=function n when n<2I->g |n->fN(n*g)(n-1I) 
let fG (n:int)(p:int)=let g,p=bigint n,bigint p in (((fN 1I (g-1I))*(fN 1I (p-g))-(-1I)**n)%(p*p))=0I
[1..11]|>List.iter(fun n->printf "%2d -> " n; let fG=fG n in pCache|>Seq.skipWhile((>)n)|>Seq.takeWhile((>)11000)|>Seq.filter fG|>Seq.iter(printf "%d "); printfn "")


  

You may also check:How to resolve the algorithm Pangram checker step by step in the Rust programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the VBScript programming language
You may also check:How to resolve the algorithm Pythagoras tree step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Five weekends step by step in the uBasic/4tH programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the C# programming language