Wieferich primes: Difference between revisions

added RPL
m (syntax highlighting fixup automation)
(added RPL)
 
(6 intermediate revisions by 4 users not shown)
Line 68:
1093
3511
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">
BEGIN # find Wierferich Primes: primes p where p^2 evenly divides 2^(p-1)-1 #
 
INT max number = 5 000; # maximum number we will consider #
# set precision of LONG LONG INT - p^5000 has over 1500 digits #
PR precision 1600 PR
PR read "primes.incl.a68" PR # include prime utlities #
# get a list of primes up to max number #
[]INT prime = EXTRACTPRIMESUPTO max number
FROMPRIMESIEVE PRIMESIEVE max number;
 
# find the primes #
INT p pos := LWB prime;
LONG LONG INT two to p minus 1 := 1;
INT power := 0;
INT w count := 0;
WHILE w count < 2 DO
INT p = prime[ p pos ];
WHILE power < ( p - 1 ) DO
two to p minus 1 *:= 2;
power +:= 1
OD;
IF ( two to p minus 1 - 1 ) MOD ( p * p ) = 0 THEN
print( ( " ", whole( p, 0 ) ) );
w count +:= 1
FI;
p pos +:= 1
OD
END
</syntaxhighlight>
{{out}}
<pre>
1093 3511
</pre>
 
Line 506 ⟶ 544:
1093
3511</pre>
 
=={{header|EasyLang}}==
{{trans|BASIC256}}
 
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func wieferich p .
if isprim p = 0
return 0
.
q = 1
p2 = p * p
while p > 1
q = (2 * q) mod p2
p -= 1
.
if q = 1
return 1
.
.
print "Wieferich primes less than 5000: "
for i = 2 to 5000
if wieferich i = 1
print i
.
.
</syntaxhighlight>
 
{{out}}
<pre>
Wieferich primes less than 5000:
1093
3511
</pre>
 
=={{header|F_Sharp|F#}}==
Line 915 ⟶ 996:
 
=={{header|Python}}==
<syntaxhighlight lang="python">#!/usr/bin/python
# Wieferich-Primzahlen
MAX: int = 5_000
 
# Berechnet a^n mod m
def isPrime(n):
def pow_mod(a: int, n: int, m: int) -> int:
assert n >= 0 and m != 0, "pow_mod(a, n, m), n >= 0, m <> 0"
res: int = 1
a %= m
while n > 0:
if n%2:
res = (res*a)%m
n -= 1
else:
a = (a*a)%m
n //= 2
return res%m
 
def is_prime(n: int) -> bool:
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
 
def isWeiferichis_wieferich(p: int) -> True:
if not isPrimeis_prime(p) == False:
return False
qif pow_mod(2, p - 1, p*p) == 1:
p2 = p ** 2
while p > 1:
q = (2 * q) % p2
p -= 1
if q == 1:
return True
else:
return False
 
 
if __name__ == '__main__':
print(f"Wieferich primes less than 5000{MAX}: ")
for i in range(2, 5001MAX + 1):
if isWeiferichis_wieferich(i):
print(i)</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>Wieferich primes less than 5000:
Line 1,039 ⟶ 1,131:
 
Found 2 Wieferich primes that are < 5,000
</pre>
 
=={{header|RPL}}==
{{works with|RPL|HP49-C}}
« { } 2
'''WHILE''' DUP 5000 < '''REPEAT'''
'''IF''' 2 OVER 1 - ^ 1 - OVER SQ MOD NOT '''THEN''' SWAP OVER + SWAP '''END'''
NEXTPRIME
'''END''' DROP
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 1093 3511 }
</pre>
 
Line 1,167 ⟶ 1,272:
{{libheader|Wren-math}}
{{libheader|Wren-big}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./big" for BigInt
 
var primes = Int.primeSieve(5000)
1,151

edits