Wilson primes of order n: Difference between revisions
Content added Content deleted
m (→{{header|jq}}: indentation) |
(add FreeBASIC) |
||
Line 220: | Line 220: | ||
10: 11 1109 |
10: 11 1109 |
||
11: 17 2713 |
11: 17 2713 |
||
</pre> |
|||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>#include "isprime.bas" |
|||
function is_wilson( n as uinteger, p as uinteger ) as boolean |
|||
'tests if p^2 divides (n-1)!(p-n)! - (-1)^n |
|||
'does NOT test the primality of p; do that first before you call this! |
|||
'using mods no big nums are required |
|||
if p<n then return false |
|||
dim as uinteger prod = 1, i, p2 = p^2 |
|||
for i = 1 to n-1 |
|||
prod = (prod*i) mod p2 |
|||
next i |
|||
for i = 1 to p-n |
|||
prod = (prod*i) mod p2 |
|||
next i |
|||
prod = (p2 + prod - (-1)^n) mod p2 |
|||
if prod = 0 then return true else return false |
|||
end function |
|||
print "n: Wilson primes" |
|||
print "--------------------" |
|||
for n as uinteger = 1 to 11 |
|||
print using "## ";n; |
|||
for p as uinteger = 3 to 10099 step 2 |
|||
if isprime(p) andalso is_wilson(n, p) then print p;" "; |
|||
next p |
|||
print |
|||
next n |
|||
</lang> |
|||
{{out}}<pre> |
|||
n: Wilson primes |
|||
-------------------- |
|||
1 5 13 563 |
|||
2 3 11 107 4931 |
|||
3 7 |
|||
4 |
|||
5 5 7 47 |
|||
6 11 |
|||
7 17 |
|||
8 |
|||
9 541 |
|||
10 11 1109 |
|||
11 17 2713 |
|||
</pre> |
</pre> |
||