#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 */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  short i;
  int t, n, sum;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 2, sum = 1; i * i <= n; ++i) {
      if (n % i == 0) {
        sum += i;
        if (n / i != i) {
          sum += n / i;
        }
      }
    }
    if (n == 1) {
      puts("0");
    } else {
      printf("%d\n", sum);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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     1221 <main+0xf1>
lea    0xe96(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
movw   $0x2,-0x6(%rbp)
movl   $0x1,-0x14(%rbp)
movswl -0x6(%rbp),%eax
movswl -0x6(%rbp),%ecx
imul   %ecx,%eax
cmp    -0x10(%rbp),%eax
jg     11f2 <main+0xc2>
mov    -0x10(%rbp),%eax
movswl -0x6(%rbp),%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11dc <main+0xac>
movswl -0x6(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
movswl -0x6(%rbp),%ecx
cltd
idiv   %ecx
movswl -0x6(%rbp),%ecx
cmp    %ecx,%eax
je     11d7 <main+0xa7>
mov    -0x10(%rbp),%eax
movswl -0x6(%rbp),%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <main+0xac>
jmp    11e1 <main+0xb1>
mov    -0x6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x6(%rbp)
jmp    1180 <main+0x50>
cmpl   $0x1,-0x10(%rbp)
jne    120d <main+0xdd>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
jmp    121c <main+0xec>
mov    -0x14(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1165 <main+0x35>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe94(%rip),%r14
lea    0xc(%rsp),%r13
lea    0xe8b(%rip),%r15
lea    0xe86(%rip),%r12
jmp    119f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <printf@plt>
subl   $0x1,0x8(%rsp)
jb     1155 <main+0x25>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r8d
mov    $0x1,%esi
cmp    $0x4,%r8d
jge    11e0 <main+0xb0>
cmp    $0x1,%r8d
jne    1190 <main+0x60>
mov    %r15,%rdi
call   1030 <puts@plt>
subl   $0x1,0x8(%rsp)
jae    119f <main+0x6f>
jmp    1155 <main+0x25>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%esi
mov    $0x2,%edi
jmp    1207 <main+0xd7>
nopl   0x0(%rax)
add    %ecx,%ebx
test   %edx,%edx
cmove  %ebx,%esi
add    $0x1,%edi
movswl %di,%edi
mov    %edi,%eax
imul   %edi,%eax
cmp    %r8d,%eax
jg     11ba <main+0x8a>
mov    %r8d,%eax
cltd
idiv   %edi
lea    (%rsi,%rdi,1),%ebx
xor    %ecx,%ecx
cmp    %edi,%eax
je     11f0 <main+0xc0>
mov    %eax,%ecx
jmp    11f0 <main+0xc0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %7
7: ; preds = %59, %0
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %60
11: ; preds = %7
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i16 2, i16* %2
store i32 1, i32* %5
br label %13
13: ; preds = %48, %11
%14 = load i16, i16* %2
%15 = sext i16 %14 to i32
%16 = load i16, i16* %2
%17 = sext i16 %16 to i32
%18 = mul nsw i32 %15, %17
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %51
21: ; preds = %13
%22 = load i32, i32* %4
%23 = load i16, i16* %2
%24 = sext i16 %23 to i32
%25 = srem i32 %22, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %47
27: ; preds = %21
%28 = load i16, i16* %2
%29 = sext i16 %28 to i32
%30 = load i32, i32* %5
%31 = add nsw i32 %30, %29
store i32 %31, i32* %5
%32 = load i32, i32* %4
%33 = load i16, i16* %2
%34 = sext i16 %33 to i32
%35 = sdiv i32 %32, %34
%36 = load i16, i16* %2
%37 = sext i16 %36 to i32
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %46
39: ; preds = %27
%40 = load i32, i32* %4
%41 = load i16, i16* %2
%42 = sext i16 %41 to i32
%43 = sdiv i32 %40, %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, %43
store i32 %45, i32* %5
br label %46
46: ; preds = %39, %27
br label %47
47: ; preds = %46, %21
br label %48
48: ; preds = %47
%49 = load i16, i16* %2
%50 = add i16 %49, 1
store i16 %50, i16* %2
br label %13
51: ; preds = %13
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %59
56: ; preds = %51
%57 = load i32, i32* %5
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %54
br label %7
60: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [4 x i8] c"%d\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 %40, label %9
9: ; preds = %0, %36
%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 = icmp slt i32 %11, 4
br i1 %12, label %29, label %13
13: ; preds = %9, %13
%14 = phi i32 [ %26, %13 ], [ 2, %9 ]
%15 = phi i32 [ %23, %13 ], [ 1, %9 ]
%16 = srem i32 %11, %14
%17 = sdiv i32 %11, %14
%18 = icmp eq i32 %16, 0
%19 = add nsw i32 %15, %14
%20 = icmp eq i32 %17, %14
%21 = select i1 %20, i32 0, i32 %17
%22 = add nsw i32 %19, %21
%23 = select i1 %18, i32 %22, i32 %15
%24 = shl nsw i32 %14, 16
%25 = add i32 %24, 65536
%26 = ashr exact i32 %25, 16
%27 = mul nsw i32 %26, %26
%28 = icmp sgt i32 %27, %11
br i1 %28, label %29, label %13
29: ; preds = %13, %9
%30 = phi i32 [ 1, %9 ], [ %23, %13 ]
%31 = icmp eq i32 %11, 1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %36
36: ; preds = %34, %32
%37 = load i32, i32* %1
%38 = add nsw i32 %37, -1
store i32 %38, i32* %1
%39 = icmp eq i32 %37, 0
br i1 %39, label %40, label %9
40: ; preds = %36, %0
ret i32 0
}