Factorial primes: Difference between revisions

Factorial primes in Gambas
(Factorial primes in various dialects BASIC (BASIC256, Run BASIC, and Yabasic))
(Factorial primes in Gambas)
Line 169:
i = i + 1
wend</syntaxhighlight>
 
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public Sub Main()
Print "First 10 factorial primes:"
Dim found As Long = 0, i As Integer = 1
While found < 10 'más de 10 es ya BigInt
Dim fct As Long = factorial(i)
If isPrime(fct - 1) Then
found += 1
Print Format$(found, "##"); ": "; Format$(i, "##"); "! - 1 = "; fct - 1
End If
If isPrime(fct + 1) Then
found += 1
Print Format$(found, "##"); ": "; Format$(i, "##"); "! + 1 = "; fct + 1
End If
i += 1
Wend
End
 
Public Sub isPrime(ValorEval As Long) As Boolean
If ValorEval < 2 Then Return False
If ValorEval Mod 2 = 0 Then Return ValorEval = 2
If ValorEval Mod 3 = 0 Then Return ValorEval = 3
Dim d As Long = 5
While d * d <= ValorEval
If ValorEval Mod d = 0 Then Return False Else d += 2
Wend
Return True
 
End Function
 
Public Function factorial(num As Integer) As Long
Dim result As Long = 1
For i As Integer = 2 To num
result *= i
Next
Return result
End</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
2,130

edits