Jump to content

Carmichael 3 strong pseudoprimes: Difference between revisions

Added Chipmunk Basic and Gambas
m (→‎{{header|Wren}}: Minor tidy)
(Added Chipmunk Basic and Gambas)
Line 471:
==={{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 ⟶ 506:
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 ⟶ 677:
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)
 
2,131

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.