Jump to content

Primality by Wilson's theorem: Difference between revisions

insert Python
m (→‎{{header|REXX}}: added wording to the REXX section header.)
(insert Python)
Line 256:
1000th through 1015th primes:
7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081</pre>
 
=={{header|Python}}==
<lang python>from math import factorial
 
def is_wprime(n):
return n > 1 and bool(n == 2 or
(n % 2 and (factorial(n - 1) + 1) % n == 0))
 
if __name__ == '__main__':
c = 100
print(f"Primes under {c}:", end='\n ')
print([n for n in range(c) if is_wprime(n)])</lang>
 
{{out}}
<pre>Primes under 100:
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]</pre>
 
 
=={{header|REXX}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.