Permutation problem

Revision en1, by ken_love_rin, 2015-09-28 05:28:04

Give an integer N (N<=5000). How many different premutations of sequence 1..n (p[1],p[2]...p[n]) so that p[i]<>i with 1<=i<=n. It means the i-th number in a permutation must be different with its index.

for example

input 2 output 1 (2,1)

input 3 output 2 {(2,3,1); (3,1,2)}

input 4 output 9

Can you give me a solution. thank you very much and sorry about my bad english. :)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ken_love_rin 2015-09-28 05:28:04 420 Initial revision (published)