Carmichael 3 strong pseudoprimes: Difference between revisions

m
→‎{{header|RPL}}: tweaked the code
m (→‎{{header|Wren}}: Minor tidy)
m (→‎{{header|RPL}}: tweaked the code)
 
(3 intermediate revisions by 3 users not shown)
Line 179:
IF is prime[ prime3 ] THEN
IF ( prime2 * prime3 ) MOD ( prime1 - 1 ) = 1 THEN
print( ( whole( prime1, 0 ), " ", whole( prime2, 0 ), " ", whole( prime3, 0 ), newline ) );
print( ( newline ) )
FI
FI
Line 218 ⟶ 219:
61 3361 4021
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">printOneLine: function [a,b,c,d]->
Line 471 ⟶ 473:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256vbnet">for i = 3 to max_sieve step 2
for i = 3 to max_sieve step 2
isprime[i] = 1
next i
Line 507 ⟶ 508:
call carmichael3(i)
next i
end</syntaxhighlight>
end
 
</syntaxhighlight>
==={{header|Chipmunk Basic}}===
{{trans|FreeBASIC}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 max_sieve = 10000000 ' 10^7
120 dim isprime(max_sieve)
130 sub carmichael3(p1)
140 if isprime(p1) = 0 then goto 440
150 for h3 = 1 to p1-1
160 t1 = (h3+p1)*(p1-1)
170 t2 = (-p1*p1) mod h3
180 if t2 < 0 then t2 = t2+h3
190 for d = 1 to h3+p1-1
200 if t1 mod d = 0 and t2 = (d mod h3) then
210 p2 = 1+int(t1/d)
220 if isprime(p2) = 0 then goto 270
230 p3 = 1+int(p1*p2/h3)
240 if isprime(p3) = 0 or ((p2*p3) mod (p1-1)) <> 1 then goto 270
250 print format$(p1,"###");" * ";format$(p2,"####");" * ";format$(p3,"#####")
260 endif
270 next d
280 next h3
290 end sub
300 'set up sieve
310 for i = 3 to max_sieve step 2
320 isprime(i) = 1
330 next i
340 isprime(2) = 1
350 for i = 3 to sqr(max_sieve) step 2
360 if isprime(i) = 1 then
370 for j = i*i to max_sieve step i*2
380 isprime(j) = 0
390 next j
400 endif
410 next i
420 for i = 2 to 61
430 carmichael3(i)
440 next i
450 end</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 639 ⟶ 679:
61 * 241 * 421
61 * 3361 * 4021</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public isprime[1000000] As Integer
 
Public Sub Main()
Dim max_sieve As Integer = 1000000
Dim i As Integer, j As Integer
'set up sieve
For i = 3 To max_sieve Step 2
isprime[i] = 1
Next
isprime[2] = 1
For i = 3 To Sqr(max_sieve) Step 2
If isprime[i] = 1 Then
For j = i * i To max_sieve Step i * 2
isprime[j] = 0
Next
End If
Next
For i = 2 To 61
If isprime[i] <> 0 Then carmichael3(i)
Next
End
 
Sub carmichael3(p1 As Integer)
Dim h3 As Integer, d As Integer
Dim p2 As Integer, p3 As Integer, t1 As Integer, t2 As Integer
For h3 = 1 To p1 - 1
t1 = (h3 + p1) * (p1 - 1)
t2 = (-p1 * p1) Mod h3
If t2 < 0 Then t2 = t2 + h3
For d = 1 To h3 + p1 - 1
If t1 Mod d = 0 And t2 = (d Mod h3) Then
p2 = 1 + (t1 \ d)
If isprime[p2] = 0 Then Continue
p3 = 1 + ((p1 * p2) \ h3)
If isprime[p3] = 0 Or ((p2 * p3) Mod (p1 - 1)) <> 1 Then Continue
Print Format$(p1, "###"); " * "; Format$(p2, "####"); " * "; Format$(p3, "#####")
End If
Next
Next
End Sub</syntaxhighlight>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbvbnet">max_sieve = 1e7
dim isprime(max_sieve)
 
Line 3,195 ⟶ 3,286:
61 3361 4021 824389441
</pre>
=={{header|RPL}}==
{{works with|HP|49}}
« { }
3 ROT '''FOR''' p1
2 p1 1 - '''FOR''' h3
1 h3 p1 + 1 - '''FOR''' d
'''IF''' h3 p1 + p1 1 - * d MOD NOT p1 SQ NEG h3 MOD d h3 MOD == AND '''THEN'''
p1 1 - h3 p1 + d IQUOT * 1 +
'''CASE'''
DUP ISPRIME? NOT '''THEN''' DROP '''END'''
p1 OVER * h3 IQUOT 1 +
DUP ISPRIME? NOT '''THEN''' DROP2 '''END'''
DUP2 * p1 1 - MOD 1 ≠ '''THEN''' DROP2 '''END'''
p1 UNROT 3 →LIST 1 →LIST +
'''END'''
'''END'''
'''NEXT'''
'''NEXT'''
p1 NEXTPRIME 1 - 'p1' STO
'''NEXT'''
» '<span style="color:blue">CARMIC</span>' STO
 
61 <span style="color:blue">CARMIC</span>
{{out}}
<pre>
1: { { 3 11 17 } { 5 29 73 } { 5 17 29 } { 5 13 17 } { 7 19 67 } { 7 31 73 } { 7 13 31 } { 7 73 103 } { 7 13 19 } { 13 61 397 } { 13 37 241 } { 13 97 421 } { 13 37 97 } { 13 37 61 } { 17 353 1201 } { 19 199 271 } { 23 199 353 } { 29 113 1093 } { 29 197 953 } { 31 991 15361 } { 31 61 631 } { 31 151 1171 } { 31 61 271 } { 31 61 211 } { 31 271 601 } { 31 181 331 } { 37 109 2017 } { 37 73 541 } { 37 613 1621 } { 37 73 181 } { 37 73 109 } { 41 1721 35281 } { 41 881 12041 } { 41 241 761 } { 41 241 521 } { 43 631 13567 } { 43 127 2731 } { 43 127 1093 } { 43 211 757 } { 43 631 1597 } { 43 127 211 } { 43 211 337 } { 43 547 673 } { 43 3361 3907 } { 47 3359 6073 } { 47 1151 1933 } { 47 3727 5153 } { 53 53 937 } { 53 157 2081 } { 53 157 521 } { 59 1451 2089 } { 61 421 12841 } { 61 181 5521 } { 61 61 1861 } { 61 61 1861 } { 61 181 1381 } { 61 541 3001 } { 61 661 2521 } { 61 241 421 } { 61 3361 4021 } }
</pre>
 
=={{header|Ruby}}==
{{works with|Ruby|1.9}}
Line 3,304 ⟶ 3,423:
61 x 3361 x 4021
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
1,150

edits