#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 *);
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int c = 0;
  int d = a;
  int y = a;
  while (1) {
    y = a;
    a = a / b;
    c = c + a;
    if (y >= b)
      a = a + (y % b);
    else
      break;
  }
  printf("%d\n", c + d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1195 <main+0x75>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x7a>
jmp    119f <main+0x7f>
jmp    1156 <main+0x36>
mov    -0x10(%rbp),%esi
add    -0x14(%rbp),%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1040 <scanf@plt>
mov    (%rsp),%r8d
mov    0x4(%rsp),%r9d
mov    %r8d,%eax
cltd
idiv   %r9d
mov    %eax,%esi
mov    %eax,%edi
cmp    %r9d,%r8d
jl     1179 <main+0x59>
mov    %r8d,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
cltd
idiv   %r9d
mov    %edx,%ecx
add    %edi,%ecx
mov    %ecx,%eax
cltd
idiv   %r9d
mov    %eax,%edi
add    %eax,%esi
cmp    %r9d,%ecx
jge    1160 <main+0x40>
mov    %edi,(%rsp)
add    %r8d,%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [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
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
store i32 0, i32* %4
%8 = load i32, i32* %2
store i32 %8, i32* %5
%9 = load i32, i32* %2
store i32 %9, i32* %6
br label %10
10: ; preds = %0, %28
%11 = load i32, i32* %2
store i32 %11, i32* %6
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = sdiv i32 %12, %13
store i32 %14, i32* %2
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = add nsw i32 %15, %16
store i32 %17, i32* %4
%18 = load i32, i32* %6
%19 = load i32, i32* %3
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %10
%22 = load i32, i32* %2
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = srem i32 %23, %24
%26 = add nsw i32 %22, %25
store i32 %26, i32* %2
br label %28
27: ; preds = %10
br label %29
28: ; preds = %21
br label %10
29: ; preds = %27
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = add nsw i32 %30, %31
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = sdiv i32 %6, %7
%9 = icmp slt i32 %6, %7
br i1 %9, label %19, label %10
10: ; preds = %0, %10
%11 = phi i32 [ %17, %10 ], [ %8, %0 ]
%12 = phi i32 [ %16, %10 ], [ %8, %0 ]
%13 = phi i32 [ %15, %10 ], [ %6, %0 ]
%14 = srem i32 %13, %7
%15 = add nsw i32 %14, %12
%16 = sdiv i32 %15, %7
%17 = add nsw i32 %16, %11
%18 = icmp slt i32 %15, %7
br i1 %18, label %19, label %10
19: ; preds = %10, %0
%20 = phi i32 [ %8, %0 ], [ %16, %10 ]
%21 = phi i32 [ %8, %0 ], [ %17, %10 ]
store i32 %20, i32* %1
%22 = add nsw i32 %21, %6
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 0
}