#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 /*<<< orphan*/ scanf(char *, int *);
int sqrt(int);
int main() {
  int t, s, i, j, a, q;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d", &a);
    if (a == 1 || a == 0) {
      printf("0\n");
      continue;
    }
    s = 1;
    q = sqrt(a);
    for (j = 2; j <= q; j++)
      if (a % j == 0)
        s = s + j + a / j;
    if (q * q == a)
      s = s - q;
    printf("%d\n", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1233 <main+0x103>
lea    0xe97(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
je     1186 <main+0x56>
cmpl   $0x0,-0x18(%rbp)
jne    1199 <main+0x69>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1225 <main+0xf5>
movl   $0x1,-0xc(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11fb <main+0xcb>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    11e8 <main+0xb8>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <main+0xbd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <main+0x82>
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1214 <main+0xe4>
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1231 <main+0xf1>
lea    0xe92(%rip),%r14
mov    %rsp,%r13
lea    0xe8f(%rip),%r15
lea    0xe84(%rip),%r12
xor    %ebp,%ebp
jmp    11b8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r8d,%eax
imul   %r8d,%eax
cmp    %edi,%eax
mov    $0x0,%eax
cmovne %eax,%r8d
sub    %r8d,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jge    1231 <main+0xf1>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%edi
cmp    $0x1,%edi
ja     11e0 <main+0xa0>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    11af <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nop
call   1060 <sqrt@plt>
mov    %eax,%r8d
mov    $0x1,%esi
mov    (%rsp),%edi
cmp    $0x2,%eax
jl     1190 <main+0x50>
mov    %r8d,%ebx
neg    %ebx
mov    $0x2,%ecx
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%eax
cltd
idiv   %ecx
add    %esi,%eax
add    %ecx,%eax
test   %edx,%edx
cmove  %eax,%esi
lea    (%rbx,%rcx,1),%eax
add    $0x1,%eax
add    $0x1,%ecx
cmp    $0x1,%eax
jne    1210 <main+0xd0>
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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