Jacobsthal numbers: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: minor tidy) |
(Added uBasic/4tH version) |
||
Line 2,727: | Line 2,727: | ||
[3, 5, 11, 43, 683, 2731, 43691, 174763, 2796203, 715827883, 2932031007403, 768614336404564651, 201487636602438195784363, 845100400152152934331135470251, 56713727820156410577229101238628035243, 62357403192785191176690552862561408838653121833643, 1046183622564446793972631570534611069350392574077339085483, 267823007376498379256993682056860433753700498963798805883563, 5562466239377370006237035693149875298444543026970449921737087520370363869220418099018130434731, 95562442332919646317117537304253622533190207882011713489066201641121786503686867002917439712921903606443] |
[3, 5, 11, 43, 683, 2731, 43691, 174763, 2796203, 715827883, 2932031007403, 768614336404564651, 201487636602438195784363, 845100400152152934331135470251, 56713727820156410577229101238628035243, 62357403192785191176690552862561408838653121833643, 1046183622564446793972631570534611069350392574077339085483, 267823007376498379256993682056860433753700498963798805883563, 5562466239377370006237035693149875298444543026970449921737087520370363869220418099018130434731, 95562442332919646317117537304253622533190207882011713489066201641121786503686867002917439712921903606443] |
||
</pre> |
</pre> |
||
=={{header|uBasic/4tH}}== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="uBasic/4tH">Dim @n(1) |
|||
x = 0 |
|||
y = 1 |
|||
p = 1 |
|||
q = -2 |
|||
Print "First 30 Jacobsthal numbers:" |
|||
c = 0 : @n(x) = 0: @n(y) = 1 |
|||
For j = 0 To 29 |
|||
c = c + 1 |
|||
Print Using " ____________#"; @n(x); |
|||
If (c % 5) = 0 Then Print |
|||
@n(x) = P * @n(y) - Q * @n(x) |
|||
Push x : x = y : y = Pop() |
|||
Next |
|||
Print : Print "First 30 Jacobsthal-Lucas numbers: " |
|||
c = 0 : @n(x) = 2: @n(y) = 1 |
|||
For j = 0 To 29 |
|||
c = c + 1 |
|||
Print Using " ____________#"; @n(x); |
|||
If (c % 5) = 0 Then Print |
|||
@n(x) = P * @n(y) - Q * @n(x) |
|||
Push x : x = y : y = Pop() |
|||
Next |
|||
Print : Print "First 20 Jacobsthal oblong numbers: " |
|||
c = 0 : @n(x) = 0: @n(y) = 1 |
|||
For j = 0 To 19 |
|||
c = c + 1 |
|||
Print Using " ____________#"; @n(x)*@n(y); |
|||
If (c % 5) = 0 Then Print |
|||
@n(x) = P * @n(y) - Q * @n(x) |
|||
Push x : x = y : y = Pop() |
|||
Next |
|||
Print : Print "First 10 Jacobsthal primes: " |
|||
c = 0 : @n(x) = 0 : @n(y) = 1 |
|||
Do |
|||
If FUNC(_isPrime(@n(x))) Then c = c + 1 : Print @n(x) |
|||
@n(x) = P * @n(y) - Q * @n(x) |
|||
Push x : x = y : y = Pop() |
|||
Until c = 10 |
|||
Loop |
|||
End |
|||
_isPrime |
|||
Param (1) |
|||
Local (1) |
|||
If (a@ < 2) Then Return (0) |
|||
If (a@ % 2) = 0 Then Return (0) |
|||
For b@ = 3 To Func(_Sqrt(a@, 0))+1 Step 2 |
|||
If (a@ % b@) = 0 Then Unloop : Return (0) |
|||
Next |
|||
Return (1) |
|||
_Sqrt |
|||
Param (2) |
|||
Local (2) |
|||
If a@ = 0 Return (0) |
|||
c@ = Max(Shl(Set(a@, a@*(10^(b@*2))), -10), 1024) |
|||
Do |
|||
d@ = (c@+a@/c@)/2 |
|||
While (c@ > d@) |
|||
c@ = d@ |
|||
Loop |
|||
Return (c@)</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>First 30 Jacobsthal numbers: |
|||
0 1 1 3 5 |
|||
11 21 43 85 171 |
|||
341 683 1365 2731 5461 |
|||
10923 21845 43691 87381 174763 |
|||
349525 699051 1398101 2796203 5592405 |
|||
11184811 22369621 44739243 89478485 178956971 |
|||
First 30 Jacobsthal-Lucas numbers: |
|||
2 1 5 7 17 |
|||
31 65 127 257 511 |
|||
1025 2047 4097 8191 16385 |
|||
32767 65537 131071 262145 524287 |
|||
1048577 2097151 4194305 8388607 16777217 |
|||
33554431 67108865 134217727 268435457 536870911 |
|||
First 20 Jacobsthal oblong numbers: |
|||
0 1 3 15 55 |
|||
231 903 3655 14535 58311 |
|||
232903 932295 3727815 14913991 59650503 |
|||
238612935 954429895 3817763271 15270965703 61084037575 |
|||
First 10 Jacobsthal primes: |
|||
3 |
|||
5 |
|||
11 |
|||
43 |
|||
683 |
|||
2731 |
|||
43691 |
|||
174763 |
|||
2796203 |
|||
715827883 |
|||
0 OK, 0:1024 </pre> |
|||
=={{header|V (Vlang)}}== |
=={{header|V (Vlang)}}== |