Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
44
Task/Twin-primes/PureBasic/twin-primes.basic
Normal file
44
Task/Twin-primes/PureBasic/twin-primes.basic
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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 paresDePrimos(limite.d)
|
||||
p1.i = 0
|
||||
p2.i = 1
|
||||
p3.i = 1
|
||||
count.i = 0
|
||||
For i.i = 5 To limite
|
||||
p3 = p2
|
||||
p2 = p1
|
||||
p1 = isPrime(i)
|
||||
If p3 And p1
|
||||
count + 1
|
||||
EndIf
|
||||
Next i
|
||||
ProcedureReturn count
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
n.i = 1
|
||||
For i.i = 1 To 6
|
||||
n = n * 10
|
||||
PrintN("pares de primos gemelos por debajo de < " + Str(n) + " : " + Str(paresDePrimos(n)))
|
||||
Next i
|
||||
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
|
||||
CloseConsole()
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue