How to resolve the algorithm Wilson primes of order n step by step in the Wren 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 Wren 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 Wren programming language
Source code in the wren programming language
import "/math" for Int
import "/big" for BigInt
import "/fmt" for Fmt
var limit = 11000
var primes = Int.primeSieve(limit)
var facts = List.filled(limit, null)
facts[0] = BigInt.one
for (i in 1...11000) facts[i] = facts[i-1] * i
var sign = 1
System.print(" n: Wilson primes")
System.print("--------------------")
for (n in 1..11) {
Fmt.write("$2d: ", n)
sign = -sign
for (p in primes) {
if (p < n) continue
var f = facts[n-1] * facts[p-n] - sign
if (f.isDivisibleBy(p*p)) Fmt.write("%(p) ", p)
}
System.print()
}
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Order programming language
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the C++ programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the Maple programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Rust programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Ruby programming language