FUNCTION
Perrin_Numbers_List
Computes the first \e n values of a Perrin sequence.
Interface
#include <codecogs/maths/combinatorics/sequences/perrin_numbers_list.h>
using namespace Maths::Combinatorics::Sequences;
This function generates an array of the first n values in the Perrin sequence, given by the following recurrent formula
$$P(n+1) = P(n-1) + P(n-2)$$
(1)
with initial values
$$P(0) = 3 \qquad P(1) = 0 \qquad P(2) = 2$$
(2)
A special property of this sequence is that, if n is a prime then it must evenly divide $P(n)$.
Example 1
#include <codecogs/maths/combinatorics/sequences/perrin_numbers_list.h>
#include <iostream>
int main() {
std::vector<int> result = Maths::Combinatorics::Sequences::perrin_numbers_list(11);
std::cout << "Number of values: " << result.size() << std::endl;
for (int i = 0; i < result.size(); i++)
std::cout << result[i] << " ";
std::cout << std::endl;
return 0;
}Output:
Number of values: 11
3 0 2 3 2 5 5 7 10 12 17References
SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html
Parameters
n
the number of Perrin numbers to generate
Returns
the first n Perrin numbers, of orders 0 through n - 1
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.