#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned long long fac(int);
int /*<<< orphan*/ printf(char *, unsigned long long);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n, num;
  unsigned long long int result, temp, sum;
  scanf("%d", &n);
  while (n--) {
    sum = 0;
    scanf("%d", &num);
    temp = fac(num);
    for (i = 0; i <= num; i++) {
      if (i % 2)
        sum = sum - (temp / fac(i));
      else
        sum = sum + (temp / fac(i));
    }
    printf("%llu\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     123f <main+0x10f>
movq   $0x0,-0x28(%rbp)
lea    0xe8e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1030 <fac@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     122a <main+0xfa>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11e5 <main+0xb5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <fac@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1217 <main+0xe7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <fac@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    121c <main+0xec>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118e <main+0x5e>
mov    -0x28(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1164 <main+0x34>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe95(%rip),%r14
mov    %rsp,%r15
lea    0xe8e(%rip),%r12
jmp    1194 <main+0x64>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1153 <main+0x23>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%edi
call   1030 <fac@plt>
cmpl   $0x0,(%rsp)
js     1180 <main+0x50>
mov    %rax,%r13
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
jmp    11de <main+0xae>
nopl   0x0(%rax)
mov    %r13,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
neg    %rcx
test   $0x1,%bpl
cmove  %rax,%rcx
add    %rcx,%rbx
cmp    (%rsp),%ebp
jge    1182 <main+0x52>
add    $0x1,%ebp
mov    %ebp,%edi
call   1030 <fac@plt>
mov    %rax,%rcx
or     %r13,%rax
shr    $0x20,%rax
jne    11c0 <main+0x90>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
jmp    11c8 <main+0x98>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %9
9: ; preds = %43, %0
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %46
13: ; preds = %9
store i64 0, i64* %7
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = call i64 @fac(i32 %15)
store i64 %16, i64* %6
store i32 0, i32* %2
br label %17
17: ; preds = %40, %13
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i32, i32* %2
%23 = srem i32 %22, 2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i64, i64* %7
%27 = load i64, i64* %6
%28 = load i32, i32* %2
%29 = call i64 @fac(i32 %28)
%30 = udiv i64 %27, %29
%31 = sub i64 %26, %30
store i64 %31, i64* %7
br label %39
32: ; preds = %21
%33 = load i64, i64* %7
%34 = load i64, i64* %6
%35 = load i32, i32* %2
%36 = call i64 @fac(i32 %35)
%37 = udiv i64 %34, %36
%38 = add i64 %33, %37
store i64 %38, i64* %7
br label %39
39: ; preds = %32, %25
br label %40
40: ; preds = %39
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %17
43: ; preds = %17
%44 = load i64, i64* %7
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %44)
br label %9
46: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %34, label %9
9: ; preds = %0, %28
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = call i64 @fac(i32 %11)
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %9, %15
%16 = phi i64 [ %24, %15 ], [ 0, %9 ]
%17 = phi i32 [ %25, %15 ], [ 0, %9 ]
%18 = and i32 %17, 1
%19 = icmp eq i32 %18, 0
%20 = call i64 @fac(i32 %17)
%21 = udiv i64 %12, %20
%22 = sub i64 0, %21
%23 = select i1 %19, i64 %21, i64 %22
%24 = add i64 %16, %23
%25 = add nuw nsw i32 %17, 1
%26 = load i32, i32* %2
%27 = icmp slt i32 %17, %26
br i1 %27, label %15, label %28
28: ; preds = %15, %9
%29 = phi i64 [ 0, %9 ], [ %24, %15 ]
%30 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %29)
%31 = load i32, i32* %1
%32 = add nsw i32 %31, -1
store i32 %32, i32* %1
%33 = icmp eq i32 %31, 0
br i1 %33, label %34, label %9
34: ; preds = %28, %0
ret i32 0
}