How to resolve the algorithm Motzkin numbers step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Motzkin numbers step by step in the PARI/GP programming language
Table of Contents
Problem Statement
The nth Motzkin number (denoted by M[n]) is the number of different ways of drawing non-intersecting chords between n points on a circle (not necessarily touching every point by a chord). By convention M[0] = 1.
Compute and show on this page the first 42 Motzkin numbers or, if your language does not support 64 bit integers, as many such numbers as you can. Indicate which of these numbers are prime.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Motzkin numbers step by step in the PARI/GP programming language
Source code in the pari/gp programming language
M=vector(41)
M[1]=1
M[2]=2
for(n=3, 41, M[n]=(M[n-1]*(2*n+1) + M[n-2]*(3*n-3))/(n+2))
M=concat([1], M)
for(n=1, 42, print(M[n]," ",isprime(M[n])))
You may also check:How to resolve the algorithm Fermat numbers step by step in the Rust programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Robotic programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Tree traversal step by step in the C++ programming language
You may also check:How to resolve the algorithm Eertree step by step in the zkl programming language