I have forgotten

COST (GBP)
0.42
0.00
0

Derangements Number

Calculates the number of derangements of \e n objects.
Controller: CodeCogs

C++
Excel

Derangements Number

 intderangements_number( int n )
A derangement of n objects is a permutation with no fixed points. If we symbolize the permutation by $\inline&space;&space;\sigma$, then for a derangment, $\inline&space;&space;\sigma(i)$ is never equal to $\inline&space;&space;i$.

The number of derangements of n objects is given by the following formula

$d(n)&space;=&space;n!&space;\cdot&space;(1&space;-&space;1/1!&space;+&space;1/2!&space;-&space;1/3!&space;+&space;\ldots&space;(-1)^n/n!)$

Based on the inclusion/exclusion law we are allowed to write

$d(n)&space;=&space;\lceil&space;n!&space;/&space;e&space;\rceil$

where $\inline&space;&space;\lceil&space;x&space;\rceil$ is the ceiling function.

Example:

#include <codecogs/maths/combinatorics/sequences/derangements_number.h>
#include <iostream>
int main()
{
for (int i = 0; i < 10; i++)
std::cout << i << " " << Maths::Combinatorics::Sequences::derangements_number(i) << std::endl;
return 0;
}

Output:

0 1
1 0
2 1
3 2
4 9
5 44
6 265
7 1854
8 14833
9 133496

References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

 n the number of objects

Returns

the number of derangements of n objects

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.