#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*/ scanf(char *, int *);
int main(void) {
  int sieve[1000000 + 1] = {0}, count = 0, i, j, num, sum[10000 + 1] = {0};
  sieve[1] = 1;
  for (i = 2;; i++) {
    if (sieve[i] == 0) {
      for (j = 2 * i; j <= 1000000; j += i)
        sieve[j] = 1;
      sum[count + 1] = i + sum[count];
      count++;
    }
    if (count == 10000)
      break;
  }
  while (1) {
    scanf("%d", &num);
    if (num == 0)
      break;
    printf("%d\n", sum[num]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3da570,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3d0910(%rbp),%rdi
xor    %esi,%esi
mov    $0x3d0904,%edx
call   1040 <memset@plt>
movl   $0x0,-0x3d0914(%rbp)
lea    -0x3da570(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c44,%edx
call   1040 <memset@plt>
movl   $0x1,-0x3d090c(%rbp)
movl   $0x2,-0x3d0918(%rbp)
movslq -0x3d0918(%rbp),%rax
cmpl   $0x0,-0x3d0910(%rbp,%rax,4)
jne    1218 <main+0xe8>
mov    -0x3d0918(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x3d091c(%rbp)
cmpl   $0xf4240,-0x3d091c(%rbp)
jg     11e3 <main+0xb3>
movslq -0x3d091c(%rbp),%rax
movl   $0x1,-0x3d0910(%rbp,%rax,4)
mov    -0x3d0918(%rbp),%eax
add    -0x3d091c(%rbp),%eax
mov    %eax,-0x3d091c(%rbp)
jmp    11aa <main+0x7a>
mov    -0x3d0918(%rbp),%ecx
movslq -0x3d0914(%rbp),%rax
add    -0x3da570(%rbp,%rax,4),%ecx
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x3da570(%rbp,%rax,4)
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0914(%rbp)
cmpl   $0x2710,-0x3d0914(%rbp)
jne    122d <main+0xfd>
jmp    1246 <main+0x116>
jmp    1232 <main+0x102>
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
jmp    1186 <main+0x56>
jmp    124b <main+0x11b>
lea    0xdae(%rip),%rdi
lea    -0x3d0920(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x3d0920(%rbp)
jne    1270 <main+0x140>
jmp    128f <main+0x15f>
movslq -0x3d0920(%rbp),%rax
mov    -0x3da570(%rbp,%rax,4),%esi
lea    0xd7e(%rip),%rdi
call   1030 <printf@plt>
jmp    124b <main+0x11b>
xor    %eax,%eax
add    $0x3da570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3da568,%rsp
lea    0x9c60(%rsp),%rdi
xor    %ebp,%ebp
mov    $0x3d0904,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x9c44,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x1,0x9c64(%rsp)
lea    0x9c70(%rsp),%rax
mov    $0x4,%ebx
mov    $0x2,%edx
mov    $0x8,%esi
jmp    11b8 <main+0x88>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rcx
mov    0x10(%rsp,%rcx,4),%edi
add    %edx,%edi
lea    0x1(%rcx),%ebp
mov    %edi,0x14(%rsp,%rcx,4)
cmp    $0x2710,%ebp
je     11f7 <main+0xc7>
add    $0x1,%rdx
add    $0x2,%rbx
add    $0x8,%rax
add    $0x4,%rsi
cmpl   $0x0,0x9c60(%rsp,%rdx,4)
jne    11a8 <main+0x78>
cmp    $0x7a120,%rdx
ja     1190 <main+0x60>
mov    %rax,%rdi
mov    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x1,(%rdi)
add    %rdx,%rcx
add    %rsi,%rdi
cmp    $0xf4241,%rcx
jb     11e0 <main+0xb0>
jmp    1190 <main+0x60>
lea    0xe02(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1251 <main+0x121>
lea    0xdec(%rip),%r14
lea    0xde2(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cltq
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1230 <main+0x100>
xor    %eax,%eax
add    $0x3da568,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1000001 x i32]
%2 = alloca i32
%3 = alloca [10001 x i32]
%4 = bitcast [1000001 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [10001 x i32]* %3 to i8*
%7 = getelementptr inbounds [1000001 x i32], [1000001 x i32]* %1, i64 0, i64 1
store i32 1, i32* %7
br label %8
8: ; preds = %36, %0
%9 = phi i64 [ %38, %36 ], [ 2, %0 ]
%10 = phi i64 [ %39, %36 ], [ 4, %0 ]
%11 = phi i32 [ %37, %36 ], [ 0, %0 ]
%12 = getelementptr inbounds [1000001 x i32], [1000001 x i32]* %1, i64 0, i64 %9
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %8
%16 = icmp ult i64 %9, 500001
br i1 %16, label %17, label %22
17: ; preds = %15, %17
%18 = phi i64 [ %20, %17 ], [ %10, %15 ]
%19 = getelementptr inbounds [1000001 x i32], [1000001 x i32]* %1, i64 0, i64 %18
store i32 1, i32* %19
%20 = add i64 %18, %9
%21 = icmp ult i64 %20, 1000001
br i1 %21, label %17, label %22
22: ; preds = %17, %15
%23 = sext i32 %11 to i64
%24 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = trunc i64 %9 to i32
%27 = add nsw i32 %25, %26
%28 = add nsw i32 %11, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 %29
store i32 %27, i32* %30
%31 = icmp eq i32 %28, 10000
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 0
br i1 %35, label %49, label %40
36: ; preds = %8, %22
%37 = phi i32 [ %28, %22 ], [ %11, %8 ]
%38 = add nuw i64 %9, 1
%39 = add i64 %10, 2
br label %8
40: ; preds = %32, %40
%41 = phi i32 [ %47, %40 ], [ %34, %32 ]
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%47 = load i32, i32* %2
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %40
49: ; preds = %40, %32
ret i32 0
}