Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Circular-primes/PureBasic/circular-primes.basic
Normal file
53
Task/Circular-primes/PureBasic/circular-primes.basic
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
Macro floor(x)
|
||||
Round(x, #PB_Round_Down)
|
||||
EndMacro
|
||||
|
||||
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 isCircularPrime(p.i)
|
||||
n.i = floor(Log(p)/Log(10))
|
||||
m.i = Pow(10, n)
|
||||
q.i = p
|
||||
For i.i = 0 To n
|
||||
If q < p Or Not isPrime(q)
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
q = (q % m) * 10 + floor(q / m)
|
||||
Next i
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
|
||||
p.i = 2
|
||||
dp.i = 1
|
||||
cont.i = 0
|
||||
PrintN("Primeros 19 primos circulares:")
|
||||
While cont < 19
|
||||
If isCircularPrime(p)
|
||||
Print(Str(p) + " ")
|
||||
cont + 1
|
||||
EndIf
|
||||
p + dp
|
||||
dp = 2
|
||||
Wend
|
||||
|
||||
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
|
||||
CloseConsole()
|
||||
Loading…
Add table
Add a link
Reference in a new issue