Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Circular-primes/FreeBASIC/circular-primes.basic
Normal file
31
Task/Circular-primes/FreeBASIC/circular-primes.basic
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#define floor(x) ((x*2.0-0.5) Shr 1)
|
||||
|
||||
Function isPrime(Byval p As Integer) As Boolean
|
||||
If p < 2 Then Return False
|
||||
If p Mod 2 = 0 Then Return p = 2
|
||||
If p Mod 3 = 0 Then Return p = 3
|
||||
Dim As Integer d = 5
|
||||
While d * d <= p
|
||||
If p Mod d = 0 Then Return False Else d += 2
|
||||
If p Mod d = 0 Then Return False Else d += 4
|
||||
Wend
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Function isCircularPrime(Byval p As Integer) As Boolean
|
||||
Dim As Integer n = floor(Log(p)/Log(10))
|
||||
Dim As Integer m = 10^n, q = p
|
||||
For i As Integer = 0 To n
|
||||
If (q < p Or Not isPrime(q)) Then Return false
|
||||
q = (q Mod m) * 10 + floor(q / m)
|
||||
Next i
|
||||
Return true
|
||||
End Function
|
||||
|
||||
Dim As Integer p = 2, dp = 1, cont = 0
|
||||
Print("Primeros 19 primos circulares:")
|
||||
While cont < 19
|
||||
If isCircularPrime(p) Then Print p;" "; : cont += 1
|
||||
p += dp: dp = 2
|
||||
Wend
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue