#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 *, unsigned long long);
scalar_t__ scanf(char *, unsigned long long *, unsigned long long *);
int main(void) {
  unsigned long long int n, k, total, numSmoked;
  while (scanf("%llu %llu", &n, &k) > 0) {
    total = n;
    numSmoked = n;
    while (numSmoked >= k) {
      total += numSmoked / k;
      numSmoked = numSmoked / k + numSmoked % k;
    }
    printf("%llu\n", total);
  }
  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    -0x18(%rbp),%rdx
call   1040 <scanf@plt>
cmp    $0x0,%rax
jle    11c0 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11ab <main+0x8b>
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    -0x30(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x28(%rbp)
jmp    115d <main+0x3d>
mov    -0x20(%rbp),%rsi
lea    0xe54(%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    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <scanf@plt>
test   %rax,%rax
jle    11bc <main+0x9c>
lea    0xebd(%rip),%r14
lea    0xeac(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbx
jmp    117b <main+0x5b>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <scanf@plt>
test   %rax,%rax
jle    11bc <main+0x9c>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rdi
mov    %rax,%rsi
jmp    11a1 <main+0x81>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %rdi
mov    %rax,%rcx
mov    %rdx,%rax
add    %rcx,%rsi
add    %rcx,%rax
cmp    %rdi,%rax
jb     1160 <main+0x40>
mov    %rax,%rcx
or     %rdi,%rcx
shr    $0x20,%rcx
jne    1190 <main+0x70>
xor    %edx,%edx
div    %edi
mov    %eax,%ecx
mov    %edx,%eax
jmp    119b <main+0x7b>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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