#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, int, int, int);
scalar_t__ scanf(char *, int *);
double sqrt(double);
int main() {
  int i;
  int nume, denom;
  int group, pos;
  while (scanf("%d\n", &i) != EOF) {
    group = (-1.0 + sqrt(1.0 + 8.0 * (double)i)) / 2.0;
    pos = i - (group * (group + 1) / 2);
    if (pos > 0) {
      group++;
    } else {
      pos = group;
    }
    if (group & 0x1) {
      nume = group + 1 - pos;
      denom = pos;
    } else {
      nume = pos;
      denom = group + 1 - pos;
    }
    printf("TERM %d IS %d/%d\n", i, nume, denom);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
je     1237 <main+0x107>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea0(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe7c(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11df <main+0xaf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e5 <main+0xb5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     120b <main+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    121d <main+0xed>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>
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    0xef2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2e93(%rip),%r12
cmp    (%r12),%rax
jne    116b <main+0x3b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xeb6(%rip),%r14
lea    0xebd(%rip),%r15
lea    0xc(%rsp),%r13
jmp    11e9 <main+0xb9>
call   1050 <sqrt@plt>
addsd  0xe83(%rip),%xmm0
mulsd  0xe83(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    0xc(%rsp),%esi
lea    0x1(%rax),%edx
mov    %edx,%ecx
imul   %eax,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
sar    %edi
mov    %esi,%ebx
sub    %edi,%ebx
test   %ebx,%ebx
cmovle %eax,%edx
cmovle %eax,%ebx
mov    %edx,%ecx
sub    %ebx,%ecx
add    $0x1,%ecx
test   $0x1,%dl
mov    %ecx,%edx
cmove  %ebx,%edx
cmovne %ebx,%ecx
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
cmp    (%r12),%rax
je     115b <main+0x2b>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
mulsd  0xe06(%rip),%xmm0
addsd  0xe06(%rip),%xmm0
ucomisd 0xe16(%rip),%xmm0
jb     1180 <main+0x50>
sqrtsd %xmm0,%xmm0
jmp    1185 <main+0x55>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
@.str.1 = [18 x i8] c"TERM %d IS %d/%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %49, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %54
11: ; preds = %7
%12 = load i32, i32* %2
%13 = sitofp i32 %12 to double
%14 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %13, double 1.000000e+00)
%15 = call double @sqrt(double %14)
%16 = fadd double -1.000000e+00, %15
%17 = fdiv double %16, 2.000000e+00
%18 = fptosi double %17 to i32
store i32 %18, i32* %5
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
%23 = mul nsw i32 %20, %22
%24 = sdiv i32 %23, 2
%25 = sub nsw i32 %19, %24
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %11
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %33
31: ; preds = %11
%32 = load i32, i32* %5
store i32 %32, i32* %6
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %5
%35 = and i32 %34, 1
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %6
%41 = sub nsw i32 %39, %40
store i32 %41, i32* %3
%42 = load i32, i32* %6
store i32 %42, i32* %4
br label %49
43: ; preds = %33
%44 = load i32, i32* %6
store i32 %44, i32* %3
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %6
%48 = sub nsw i32 %46, %47
store i32 %48, i32* %4
br label %49
49: ; preds = %43, %37
%50 = load i32, i32* %2
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %51, i32 %52)
br label %7
54: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
@.str.1 = [18 x i8] c"TERM %d IS %d/%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %32, label %6
6: ; preds = %0, %6
%7 = load i32, i32* %1
%8 = sitofp i32 %7 to double
%9 = call double @llvm.fmuladd.f64(double %8, double 8.000000e+00, double 1.000000e+00)
%10 = call double @sqrt(double %9)
%11 = fadd double %10, -1.000000e+00
%12 = fmul double %11, 5.000000e-01
%13 = fptosi double %12 to i32
%14 = load i32, i32* %1
%15 = add nsw i32 %13, 1
%16 = mul nsw i32 %15, %13
%17 = sdiv i32 %16, -2
%18 = add i32 %17, %14
%19 = icmp sgt i32 %18, 0
%20 = select i1 %19, i32 %15, i32 %13
%21 = select i1 %19, i32 %18, i32 %13
%22 = and i32 %20, 1
%23 = icmp eq i32 %22, 0
%24 = add nsw i32 %20, 1
%25 = sub i32 %24, %21
%26 = select i1 %23, i32 %21, i32 %25
%27 = select i1 %23, i32 %25, i32 %21
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %26, i32 %27)
%29 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %6
32: ; preds = %6, %0
ret i32 0
}