Jacobsthal numbers: Difference between revisions

Added Gambas
(Added Gambas)
Line 1,380:
2796203
715827883</pre>
 
=={{header|Gambas}}==
<syntaxhighlight lang="vbnet">Public n As New Long[2]
 
Public Sub Main()
Dim i0 As Integer = 0, i1 As Integer = 1
Dim j As Integer, c As Integer, P As Integer = 1, Q As Integer = -2
Print "First 30 Jacobsthal numbers:"
c = 0
n[i0] = 0
n[i1] = 1
For j = 0 To 29
c += 1
Print Format$(n[i0], " #########");
If (c Mod 5) Then
Print "";
Else
Print Chr(10);
End If
n[i0] = P * n[i1] - Q * n[i0]
Swap i0, i1
Next
Print "\n\nFirst 30 Jacobsthal-Lucas numbers: "
c = 0
n[i0] = 2
n[i1] = 1
For j = 0 To 29
c += 1
Print Format$(n[i0], " #########");
If (c Mod 5) Then
Print "";
Else
Print Chr(10);
End If
n[i0] = P * n[i1] - Q * n[i0]
Swap i0, i1
Next
Print "\n\nFirst 20 Jacobsthal oblong numbers: "
c = 0
n[i0] = 0
n[i1] = 1
For j = 0 To 19
c += 1
Print Format$(n[i0] * n[i1], " ###########");
If (c Mod 5) Then
Print "";
Else
Print Chr(10);
End If
n[i0] = P * n[i1] - Q * n[i0]
Swap i0, i1
Next
Print "\n\nFirst 10 Jacobsthal primes: "
c = 0
n[i0] = 0
n[i1] = 1
Do
If isPrime(n[i0]) Then
c += 1
Print n[i0]
End If
n[i0] = P * n[i1] - Q * n[i0]
Swap i0, i1
Loop Until c = 10
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 </syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|Go}}==
2,130

edits