#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 fabs(double);
double log(double);
int pow(double, double);
int /*<<< orphan*/ printf(char *, double, double);
scalar_t__ scanf(char *, double *, double *);
int main() {
  double m, n;
  double i, j;
  double sum;
  while (scanf("%lf%lf", &n, &m) != EOF) {
    if (m == 0 && n == 0)
      break;
    if (m == 1) {
      printf("%.0lf %.0lf\n", log(n) / log(2), n * 2 - 1);
      continue;
    }
    i = 1;
    while (fabs(log(i + 1) / log(i) - log(n) / log(m)) > 1e-8)
      i++;
    j = log(m) / log(i);
    sum = m * (pow((i + 1) / i, j + 1) - 1) / ((i + 1) / i - 1);
    printf("%.0lf %.0lf\n", (m - 1) / (i - 1), sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <scanf@plt>
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
je     138d <main+0x23d>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b8 <main+0x68>
jp     11b8 <main+0x68>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b8 <main+0x68>
jp     11b8 <main+0x68>
jmp    138d <main+0x23d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1223 <main+0xd3>
jp     1223 <main+0xd3>
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe2c(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe02(%rip),%xmm2
addsd  %xmm2,%xmm1
lea    0xe0e(%rip),%rdi
call   1030 <printf@plt>
jmp    115f <main+0xf>
movsd  0xdd5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdc8(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd67(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c2 <main+0x172>
movsd  0xd4d(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1230 <main+0xe0>
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xd02(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xcf0(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
call   1070 <pow@plt>
movsd  -0x58(%rbp),%xmm0
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcce(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movsd  0xcbc(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xca2(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xc91(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xca4(%rip),%rdi
call   1030 <printf@plt>
jmp    115f <main+0xf>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
lea    0xebc(%rip),%rdi
lea    0x18(%rsp),%rsi
mov    %rsp,%rdx
call   1050 <scanf@plt>
mov    0x2e70(%rip),%rbx
cmp    (%rbx),%rax
jne    118d <main+0x3d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movsd  0xe6b(%rip),%xmm2
lea    0xe8b(%rip),%r14
lea    0xe7d(%rip),%r15
lea    0x18(%rsp),%r12
mov    %rsp,%r13
jmp    11fa <main+0xaa>
nopl   (%rax)
ucomisd %xmm2,%xmm1
jne    1230 <main+0xe0>
jp     1230 <main+0xe0>
call   1060 <log@plt>
divsd  0xe4b(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  0xe31(%rip),%xmm1
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <scanf@plt>
cmp    (%rbx),%rax
movsd  0xe08(%rip),%xmm2
je     117d <main+0x2d>
movsd  (%rsp),%xmm1
ucomisd 0xe11(%rip),%xmm1
movsd  0x18(%rsp),%xmm0
jne    11b0 <main+0x60>
jp     11b0 <main+0x60>
ucomisd 0xdff(%rip),%xmm0
jne    11b0 <main+0x60>
jp     11b0 <main+0x60>
jmp    117d <main+0x2d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm2,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  0xdac(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <log@plt>
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
movaps %xmm0,0x40(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <log@plt>
movaps %xmm0,0x30(%rsp)
movsd  (%rsp),%xmm0
call   1060 <log@plt>
movapd 0x20(%rsp),%xmm1
unpcklpd 0x30(%rsp),%xmm1
movapd 0x40(%rsp),%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jg     1240 <main+0xf0>
movsd  (%rsp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
addsd  0xcf0(%rip),%xmm1
call   1070 <pow@plt>
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0x20(%rsp),%xmm1
movsd  0xcdb(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm3
addsd  %xmm2,%xmm3
divsd  %xmm3,%xmm0
jmp    11d7 <main+0x87>

LLVM IR (-O0):
@.str = [7 x i8] c"%lf%lf\00"
@EOF = global i64 0
@.str.1 = [13 x i8] c"%.0lf %.0lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i32 0, i32* %1
br label %7
7: ; preds = %49, %21, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %3, double* %2)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %79
11: ; preds = %7
%12 = load double, double* %2
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load double, double* %3
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %14
br label %79
18: ; preds = %14, %11
%19 = load double, double* %2
%20 = fcmp oeq double %19, 1.000000e+00
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load double, double* %3
%23 = call double @log(double %22)
%24 = call double @log(double 2.000000e+00)
%25 = fdiv double %23, %24
%26 = load double, double* %3
%27 = call double @llvm.fmuladd.f64(double %26, double 2.000000e+00, double -1.000000e+00)
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %25, double %27)
br label %7
29: ; preds = %18
store double 1.000000e+00, double* %4
br label %30
30: ; preds = %46, %29
%31 = load double, double* %4
%32 = fadd double %31, 1.000000e+00
%33 = call double @log(double %32)
%34 = load double, double* %4
%35 = call double @log(double %34)
%36 = fdiv double %33, %35
%37 = load double, double* %3
%38 = call double @log(double %37)
%39 = load double, double* %2
%40 = call double @log(double %39)
%41 = fdiv double %38, %40
%42 = fsub double %36, %41
%43 = call i32 @fabs(double %42)
%44 = sitofp i32 %43 to double
%45 = fcmp ogt double %44, 1.000000e-08
br i1 %45, label %46, label %49
46: ; preds = %30
%47 = load double, double* %4
%48 = fadd double %47, 1.000000e+00
store double %48, double* %4
br label %30
49: ; preds = %30
%50 = load double, double* %2
%51 = call double @log(double %50)
%52 = load double, double* %4
%53 = call double @log(double %52)
%54 = fdiv double %51, %53
store double %54, double* %5
%55 = load double, double* %2
%56 = load double, double* %4
%57 = fadd double %56, 1.000000e+00
%58 = load double, double* %4
%59 = fdiv double %57, %58
%60 = load double, double* %5
%61 = fadd double %60, 1.000000e+00
%62 = call i32 @pow(double %59, double %61)
%63 = sub nsw i32 %62, 1
%64 = sitofp i32 %63 to double
%65 = fmul double %55, %64
%66 = load double, double* %4
%67 = fadd double %66, 1.000000e+00
%68 = load double, double* %4
%69 = fdiv double %67, %68
%70 = fsub double %69, 1.000000e+00
%71 = fdiv double %65, %70
store double %71, double* %6
%72 = load double, double* %2
%73 = fsub double %72, 1.000000e+00
%74 = load double, double* %4
%75 = fsub double %74, 1.000000e+00
%76 = fdiv double %73, %75
%77 = load double, double* %6
%78 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %76, double %77)
br label %7
79: ; preds = %17, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%lf%lf\00"
@EOF = global i64 0
@.str.1 = [13 x i8] c"%.0lf %.0lf\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %2, double* %1)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %64, label %8
8: ; preds = %0, %22
%9 = load double, double* %1
%10 = fcmp oeq double %9, 0.000000e+00
%11 = load double, double* %2
%12 = fcmp oeq double %11, 0.000000e+00
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %64, label %14
14: ; preds = %8
%15 = fcmp oeq double %9, 1.000000e+00
br i1 %15, label %16, label %26
16: ; preds = %14
%17 = call double @log(double %11)
%18 = fdiv double %17, 0x3FE62E42FEFA39EF
%19 = load double, double* %2
%20 = call double @llvm.fmuladd.f64(double %19, double 2.000000e+00, double -1.000000e+00)
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %18, double %20)
br label %22
22: ; preds = %16, %45
%23 = call i64 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %2, double* %1)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %64, label %8
26: ; preds = %14, %26
%27 = phi double [ %28, %26 ], [ 1.000000e+00, %14 ]
%28 = fadd double %27, 1.000000e+00
%29 = call double @log(double %28)
%30 = call double @log(double %27)
%31 = load double, double* %2
%32 = call double @log(double %31)
%33 = load double, double* %1
%34 = call double @log(double %33)
%35 = insertelement <2 x double> poison, double %29, i64 0
%36 = insertelement <2 x double> %35, double %32, i64 1
%37 = insertelement <2 x double> poison, double %30, i64 0
%38 = insertelement <2 x double> %37, double %34, i64 1
%39 = fdiv <2 x double> %36, %38
%40 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%41 = fsub <2 x double> %39, %40
%42 = extractelement <2 x double> %41, i64 0
%43 = call i32 @fabs(double %42)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %26, label %45
45: ; preds = %26
%46 = load double, double* %1
%47 = call double @log(double %46)
%48 = call double @log(double %27)
%49 = fdiv double %47, %48
%50 = load double, double* %1
%51 = fdiv double %28, %27
%52 = fadd double %49, 1.000000e+00
%53 = call i32 @pow(double %51, double %52)
%54 = add nsw i32 %53, -1
%55 = sitofp i32 %54 to double
%56 = fmul double %50, %55
%57 = fadd double %51, -1.000000e+00
%58 = fdiv double %56, %57
%59 = load double, double* %1
%60 = fadd double %59, -1.000000e+00
%61 = fadd double %27, -1.000000e+00
%62 = fdiv double %60, %61
%63 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %62, double %58)
br label %22
64: ; preds = %22, %8, %0
ret i32 0
}