Safe and Sophie Germain primes: Difference between revisions

Safe and Sophie Germain primes in various BASIC dialents
(Added 11l)
(Safe and Sophie Germain primes in various BASIC dialents)
Line 108:
od;</lang>
 
=={{header|FreeBASICBASIC}}==
==={{header|FreeBASIC}}===
<lang freebasic>function isprime(n as integer) as boolean
if n < 2 then return false
Line 139 ⟶ 140:
113 131 173 179 191 233 239 251 281 293
359 419 431 443 491 509 593 641 653 659
683 719 743 761 809 911 953 1013 1019 1031
1049 1103 1223 1229 1289 1409 1439 1451 1481 1499</pre>
</pre>
 
==={{header|GW-BASIC}}===
<lang gwbasic>10 PRINT "2 ";
20 C = 1
Line 173:
280 Z = 1
290 RETURN</lang>
 
==={{header|BASIC256}}===
<lang freebasic>function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 3 = 0 then return v = 3
d = 5
while d * d <= v
if v mod d = 0 then return False else d += 2
end while
return True
end function
 
function isSG(n)
if not isPrime(n) then return False
return isPrime(2*n+1)
end function
 
c = 1
i = 1
print "2 ";
while c < 50
i += 2
if isSG(i) then
print i; chr(9);
c += 1
if c mod 10 = 0 then print
end if
end while
end</lang>
 
==={{header|PureBasic}}===
<lang PureBasic>Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
ElseIf v % 2 = 0 : ProcedureReturn #False
ElseIf v < 9 : ProcedureReturn #True
ElseIf v % 3 = 0 : ProcedureReturn #False
Else
Protected r = Round(Sqr(v), #PB_Round_Down)
Protected f = 5
While f <= r
If v % f = 0 Or v % (f + 2) = 0 :
ProcedureReturn #False
EndIf
f + 6
Wend
EndIf
ProcedureReturn #True
EndProcedure
 
Procedure isSG(n.i)
If Not isPrime(n) : ProcedureReturn #False : EndIf
ProcedureReturn isPrime(2*n+1)
EndProcedure
 
OpenConsole()
c.i = 1
i.i = 1
Print("2 ")
While c < 50
i + 2
If isSG(i):
Print(Str(i) + #TAB$)
c + 1
If c % 10 = 0 : PrintN("") : EndIf
EndIf
Wend
Input()
CloseConsole()</lang>
 
==={{header|Yabasic}}===
<lang freebasic>sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 3) = 0 then return v = 3 : fi
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub
 
sub isSG(n)
if not isPrime(n) then return False : fi
return isPrime(2*n+1)
end sub
 
c = 1
i = 1
print "2 ";
while c < 50
i = i + 2
if isSG(i) then
print i, " ";
c = c + 1
if mod(c, 10) = 0 then print : fi
endif
wend
end</lang>
 
=={{header|jq}}==
2,122

edits