#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 *, long long *);
int main() {
  int cnt;
  long long int n, i;
  scanf("%lld", &n);
  while (n) {
    for (i = 2; i * i <= n; ++i) {
      cnt = 0;
      while (n % i == 0) {
        n /= i;
        ++cnt;
      }
      if (cnt) {
        printf("%lld^%d", i, cnt);
        if (n > 1)
          printf(" ");
        cnt = 0;
      }
    }
    if (n > 1)
      printf("%lld^%d\n", n, 1);
    else
      printf("\n");
    scanf("%lld", &n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     123e <main+0x11e>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     11f4 <main+0xd4>
movl   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    119f <main+0x7f>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x4c>
cmpl   $0x0,-0x8(%rbp)
je     11de <main+0xbe>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x1,-0x10(%rbp)
jle    11d7 <main+0xb7>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
jmp    11e3 <main+0xc3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1152 <main+0x32>
cmpq   $0x1,-0x10(%rbp)
jle    121b <main+0xfb>
mov    -0x10(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1229 <main+0x109>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    113f <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>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     1297 <main+0x167>
lea    0xeaa(%rip),%r14
lea    0xe96(%rip),%r15
lea    0x8(%rsp),%r12
lea    0xe8f(%rip),%r13
jmp    11a3 <main+0x73>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     1297 <main+0x167>
cmp    $0x4,%rsi
jge    11c0 <main+0x90>
cmp    $0x2,%rsi
jl     1180 <main+0x50>
mov    %r14,%rdi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118a <main+0x5a>
mov    $0x2,%ebx
jmp    11e0 <main+0xb0>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%rax
imul   %rbx,%rax
cmp    %rsi,%rax
jg     11a9 <main+0x79>
mov    %rsi,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1200 <main+0xd0>
mov    %rsi,%rax
cqto
idiv   %rbx
test   %rdx,%rdx
jne    11d0 <main+0xa0>
jmp    120b <main+0xdb>
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    11d0 <main+0xa0>
xor    %ecx,%ecx
jmp    1220 <main+0xf0>
nop
mov    %rsi,%rax
cqto
idiv   %rbx
add    $0x1,%ecx
test   %rdx,%rdx
jne    1260 <main+0x130>
mov    %rsi,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1240 <main+0x110>
mov    %rsi,%rax
cqto
idiv   %rbx
mov    %rax,%rsi
jmp    1248 <main+0x118>
nopl   0x0(%rax)
mov    %esi,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%esi
mov    %rsi,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1210 <main+0xe0>
mov    %esi,%eax
xor    %edx,%edx
div    %ebx
jmp    1218 <main+0xe8>
nopl   0x0(%rax)
mov    %rsi,0x8(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    $0x2,%rsi
jl     11d0 <main+0xa0>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rsi
jmp    11d0 <main+0xa0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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