Aggressive rooks

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.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:05:02.432Z

© Jutge.org, 2006–2026.
https://jutge.org