Page 1 of 1

math, primes : Wilson theorem

Posted: Sat Oct 01, 2022 7:12 pm
by Olli
Code to understand this crazy rule :

Code: Select all

Dim s.s(1)
s(0) = " = 0 so it's a prime"
fact + 1
Debug Chr($8000)
For n = 2 To 21
   Debug Rset(Str(fact + 1), 24, " ") + "+1  % " + Str(n) + s(Bool((fact + 1) % n) )
   fact * n
Next

Re: math, primes : Wilson theorem

Posted: Fri Oct 07, 2022 3:41 am
by Olli

Code: Select all

Procedure isPrime(p)
   Protected a = p - 1
   Protected b
   For i = p - 2 To 2 Step -1
      a * i
      a % p
   Next
   a + 1
   ProcedureReturn Bool(a = p)
EndProcedure