#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 *, long long);
int scanf(char *, long long *, long long *);
int main(void) {
  long long int n, i, k;
  while (scanf("%lld %lld\n", &n, &k) == 2) {
    i = n;
    while (n >= k) {
      i += n / k;
      n = n / k + n % k;
    }
    printf("%lld\n", i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    11b1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     119c <main+0x7c>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    -0x28(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x10(%rbp)
jmp    1154 <main+0x34>
mov    -0x18(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xece(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    11dc <main+0xbc>
lea    0xeb4(%rip),%r14
lea    0xea8(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
jmp    1190 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    11dc <main+0xbc>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdi
mov    %rsi,%rax
cmp    %rdi,%rsi
jge    11c6 <main+0xa6>
jmp    1175 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cqto
idiv   %rdi
mov    %rax,%rcx
mov    %rdx,%rax
add    %rcx,%rsi
add    %rcx,%rax
cmp    %rdi,%rax
jl     1170 <main+0x50>
mov    %rax,%rcx
or     %rdi,%rcx
shr    $0x20,%rcx
jne    11b0 <main+0x90>
xor    %edx,%edx
div    %edi
mov    %eax,%ecx
mov    %edx,%eax
jmp    11bb <main+0x9b>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%lld %lld\0A\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %25
7: ; preds = %0, %20
%8 = load i64, i64* %1
%9 = load i64, i64* %2
%10 = icmp slt i64 %8, %9
br i1 %10, label %20, label %11
11: ; preds = %7, %11
%12 = phi i64 [ %15, %11 ], [ %8, %7 ]
%13 = phi i64 [ %17, %11 ], [ %8, %7 ]
%14 = sdiv i64 %13, %9
%15 = add nsw i64 %14, %12
%16 = srem i64 %13, %9
%17 = add nsw i64 %16, %14
%18 = icmp slt i64 %17, %9
br i1 %18, label %19, label %11
19: ; preds = %11
store i64 %17, i64* %1
br label %20
20: ; preds = %19, %7
%21 = phi i64 [ %15, %19 ], [ %8, %7 ]
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %21)
%23 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%24 = icmp eq i32 %23, 2
br i1 %24, label %7, label %25
25: ; preds = %20, %0
ret i32 0
}