James's hard work time limit: 3000 MS | memory limit: 65535 KB difficulty: 2
-
Description
-
In class, James learned to use a computer to find the N factorial. When he got home, he showed off to his sister. In order not to let my brother be too complacent, my sister gave James a question: "Since you will ask for the n factorial, you can help me calculate 1! + 2! -3! + 4! -5! + ...... N !". Now James is in trouble.
Are you smart enough to help him?
-
Input
-
In the first line, enter an integer T (0 <t <= 20), which indicates that there are T groups of test data.
There are t rows, and each row enters a positive integer N (0 <n <= 20 ).
-
Output
-
Each group of test data occupies one row. Output 1! + 2! -3! + ..... N! .
-
Sample Input
-
224
-
Sample output
-
321
# Include <stdio. h> # include <stdlib. h> int main () {int n, m, I, j; long sum, JI; scanf ("% d", & N); While (n --) {scanf ("% d", & M); sum = 1; for (I = 2; I <= m; I ++) {Ji = 1; for (j = 1; j <= I; j ++) {Ji * = J;} if (I> 1) if (I % 2 = 0) sum + = Ji; elsesum-= Ji;} printf ("% LLD \ n", sum);} return 0 ;}