How to resolve the algorithm Jacobsthal numbers step by step in the XPL0 programming language
How to resolve the algorithm Jacobsthal numbers step by step in the XPL0 programming language
Table of Contents
Problem Statement
Jacobsthal numbers are an integer sequence related to Fibonacci numbers. Similar to Fibonacci, where each term is the sum of the previous two terms, each term is the sum of the previous, plus twice the one before that. Traditionally the sequence starts with the given terms 0, 1. Terms may be calculated directly using one of several possible formulas:
Jacobsthal-Lucas numbers are very similar. They have the same recurrence relationship, the only difference is an initial starting value J0 = 2 rather than J0 = 0. Terms may be calculated directly using one of several possible formulas: Jacobsthal oblong numbers is the sequence obtained from multiplying each Jacobsthal number Jn by its direct successor Jn+1.
Jacobsthal primes are Jacobsthal numbers that are prime.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Jacobsthal numbers step by step in the XPL0 programming language
Source code in the xpl0 programming language
func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
proc Jaco(J2); \Display 30 Jacobsthal (or -Lucas) numbers
real J2, J1, J;
int N;
[RlOut(0, J2);
J1:= 1.0;
RlOut(0, J1);
for N:= 2 to 30-1 do
[J:= J1 + 2.0*J2;
RlOut(0, J);
if rem((N+1)/5) = 0 then CrLf(0);
J2:= J1; J1:= J;
];
CrLf(0);
];
real J, J1, J2, JO;
int N;
[Format(14, 0);
Jaco(0.0);
Jaco(2.0);
J2:= 1.0;
RlOut(0, 0.0);
J1:= 1.0;
RlOut(0, J1);
for N:= 2 to 20-1 do
[J:= (J1 + 2.0*J2);
JO:= J*J1;
RlOut(0, JO);
if rem((N+1)/5) = 0 then CrLf(0);
J2:= J1; J1:= J;
];
CrLf(0);
J2:= 0.0; J1:= 1.0; N:= 0;
loop [J:= J1 + 2.0*J2;
if IsPrime(fix(J)) then
[RlOut(0, J);
N:= N+1;
if rem(N/5) = 0 then CrLf(0);
if N >= 10 then quit;
];
J2:= J1; J1:= J;
];
]
You may also check:How to resolve the algorithm Middle three digits step by step in the NetRexx programming language
You may also check:How to resolve the algorithm One of n lines in a file step by step in the 11l programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Solve a Hopido puzzle step by step in the Ruby programming language
You may also check:How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the C programming language