Carmichael 3 strong pseudoprimes: Difference between revisions

Carmichael 3 strong pseudoprimes in Yabasic
(added Arturo)
(Carmichael 3 strong pseudoprimes in Yabasic)
Line 3,857:
61 3361 4021 824389441
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">max_sieve = 1e7
dim isprime(max_sieve)
 
//set up sieve
for i = 3 to max_sieve step 2
isprime(i) = 1
next i
 
isprime(2) = 1
for i = 3 to sqrt(max_sieve) step 2
if isprime(i) = 1 then
for j = i * i to max_sieve step i * 2
isprime(j) = 0
next j
fi
next i
 
for i = 2 to 61
carmichael3(i)
next i
end
sub carmichael3(p1)
local h3, d, p2, p3, t1, t2
 
if isprime(p1) = 0 return
for h3 = 1 to p1 -1
t1 = (h3 + p1) * (p1 -1)
t2 = mod((-p1 * p1), h3)
if t2 < 0 t2 = t2 + h3
for d = 1 to h3 + p1 -1
if mod(t1, d) = 0 and t2 = mod(d, h3) then
p2 = 1 + int(t1 / d)
if isprime(p2) = 0 continue
p3 = 1 + int(p1 * p2 / h3)
if isprime(p3) = 0 or mod((p2 * p3), (p1 -1)) <> 1 continue
print p1 using ("###"), " * ", p2 using ("####"), " * ", p3 using ("#####")
fi
next d
next h3
end sub</syntaxhighlight>
 
=={{header|zkl}}==
Using the Miller-Rabin primality test in lib GMP.
2,148

edits