Very Simple Question Returns
All submissions for this problem are available.
Hogwarts, a school for magic, has N students. It is organizing a magic competition in which a ball is given to every student . A distinct number is written on each ball which is between 1 to N and there are N holes in the wall far away from them and on each hole a single number is written from 1 to N. By their magic they have to put their balls into these holes.It is guaranteed that if any student throws a ball it will definitely go into one of these holes. A student will win the game if his/her ball goes inside the hole with same number as on ball.
Mr. Chulbul Pandey, the dean of the school, wants to calculate number of ways in which none of the students win the game i.e. no ball goes into its corresponding hole.
To calculate the number of ways seems to be a very simple task, so he gave Harry Potter this simple question as an assignment. Since, you and Harry are good friends , help Harry to calculate the number of ways.
1. One hole can contain only one ball.
2. There can be more than one winner.
The first line of input contains a single integer T denoting number of test cases.
Each testcase consist of a single Integer N.
Print T lines, each line has answer of each test case.
Since Answer can be large print it modulo 109 + 7.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 105
Subtask #1 : (8 points)
Subtask #2 : (12 points)
Subtask #3 : (80 points)
In Second test case there are two ways in which no student wins
1. Ball 1 will go in hole 2 , ball 2 will go in hole 3 and ball 3 will go into hole 1.
2. Ball 1 will go in hole 3 , ball 2 will go in hole 1 and ball 3 will go into hole 2.
|Tags||abhishek20113, combinatorics, counting, derangement, locapr16, mathematics, maths|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions