3857 - University Gifts

Created by Yosvany Leyva Pizarroza
Added by ypizarroza (2017-06-22)
Limits
Total Time: 2000 MS | Test Time: 1000 MS |Memory: 512 MB | Output: 64 MB | Size: 16 KB
Enabled languages
Available in

Description

Will and his friends plan to have a big exchange of gifts for Valentine's Day among all the students of his university. Byron, one of Will's friends, quickly took advantage of this situation to propose the following challenge: given an integer N representing the number of active students enrolled in the university, determine the number of ways to have the exchange of gifts where all the following conditions hold:
  1. Each student gives exactly one present (to some other student)
  2. Each student receives exactly one present (from some other student, not necessarily the same student that he (she) gives his (her) present to
  3. No student gives a present to himself (herself)
Para el Día de La Amistad, Will y sus amigos planean realizar un gran intercambio de regalos entre los estudiantes de su universidad. Byron, uno de sus amigos, aprovecha la ocasión para proponer el siguiente reto: dado un número entero N representando la cantidad de estudiantes activos registrados en la universidad, determina la cantidad de formas de organizar el intercambio de tal manera que se cumplan las siguientes condiciones:
  1. Cada estudiante obsequia exactamente un regalo (a otro estudiante)
  2. Cada estudiante recibe exactamente un regalo (de otro estudiante, no necesariamente el mismo al cual él (o ella) le obsequió su regalo)
  3. Ningún estudiante se obsequia a si mismo
;jsessionid=145114A300511F102C64EAFF703CDAFF
Will and his friends plan to have a big exchange of gifts for Valentine's Day among all the students of his university. Byron, one of Will's friends, quickly took advantage of this situation to propose the following challenge: given an integer N representing the number of active students enrolled in the university, determine the number of ways to have the exchange of gifts where all the following conditions hold:
  1. Each student gives exactly one present (to some other student)
  2. Each student receives exactly one present (from some other student, not necessarily the same student that he (she) gives his (her) present to
  3. No student gives a present to himself (herself)

Input specification

The first line in the input contain a number T (T < 103), the number of cases to process. Each of the following T lines of the entry contains an integer N (1 < N ≤ 106), which corresponds to the number of active students at Will's university.

La primera línea de entrada contiene un número entero T (T < 103), la cantidad de casos a procesar. Cada una de las siguientes T líneas contiene un entero N (1 < N ≤ 106), el cual corresponde a la cantidad de estudiantes activos registrados en la universidad.
The first line in the input contain a number T (T < 103), the number of cases to process. Each of the following T lines of the entry contains an integer N (1 < N ≤ 106), which corresponds to the number of active students at Will's university.

Output specification

For each test case, in the order given in the input, print the number of ways to exchange gifts satisfying the restrictions described above. Since this number may be quite large, print the remainder of this number when divided by 1000000007.
Por cada caso de prueba, en el orden dado de entrada, imprima la cantidad de maneras de realizar el intercambio y que se cumplan las restricciones descritas arriba. Como este número pudiera ser grande, imprima el remanente de dividir este número por 1000000007.
;jsessionid=145114A300511F102C64EAFF703CDAFF
The first line in the input contain a number T (T < 103), the number of cases to process. Each of the following T lines of the entry contains an integer N (1 < N ≤ 106), which corresponds to the number of active students at Will's university.

Sample input

3
2
3
4

Sample output

1
2
9

Hint(s)

http://coj.uci.cu/contest/
http://coj.uci.cu/contest/
http://coj.uci.cu/contest/