I have forgotten

• https://me.yahoo.com
COST (GBP)
0.42
0.00
0

Derangements Number

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

C++
Excel
HTML

Derangements Number

 intderangements_number( int n )
A derangement of n objects is a permutation with no fixed points. If we symbolize the permutation by , then for a derangment, is never equal to .

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

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

where 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.