Aggressive rooks P94143


Statement
 

pdf   zip

Consider a chessboard with nn rows and nn columns. In how many ways can we place nn rooks so that at least two rooks threaten each other?

For instance, these are two of the ways for n=6n = 6:

Input

Input consists of several numbers 1n61\leq n\leq 6. A special case with n=0n = 0 marks the end of input.

Output

For every nn, print the number of different ways to place nn rooks on a chessboard n×nn \times n so that at least two rooks threaten each other. For every 1n61\leq n\leq 6, this number has less than 10 digits.

Public test cases
  • Input

    2
    3
    0
    

    Output

    4
    78
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++