#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 gcd(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int sqrt(int);
int main() {
  int g, l;
  scanf("%d%d", &g, &l);
  int prod = l / g, i, ans = 0x7fffffff;
  for (i = 1; i <= sqrt(prod); ++i)
    if (prod % i == 0 && gcd(i, prod / i) == 1 && i + prod / i < ans)
      ans = i + prod / i;
  printf("%d\n", ans * g);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x10(%rbp)
movl   $0x7fffffff,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     1207 <main+0xc7>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    11f4 <main+0xb4>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%esi
call   1050 <gcd@plt>
cmp    $0x1,%eax
jne    11f4 <main+0xb4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
cmp    -0x18(%rbp),%eax
jge    11f4 <main+0xb4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    11f9 <main+0xb9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <main+0x3b>
mov    -0x18(%rbp),%esi
imul   -0x8(%rbp),%esi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
cltd
idivl  (%rsp)
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <sqrt@plt>
test   %eax,%eax
jle    11b6 <main+0x76>
mov    $0x1,%ebp
mov    $0x7fffffff,%r14d
jmp    1191 <main+0x51>
xchg   %ax,%ax
lea    0x1(%rbp),%ebx
mov    %r15d,%edi
call   1060 <sqrt@plt>
cmp    %eax,%ebp
mov    %ebx,%ebp
jge    11bc <main+0x7c>
mov    %r15d,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    1180 <main+0x40>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <gcd@plt>
cmp    $0x1,%eax
jne    1180 <main+0x40>
add    %ebp,%ebx
cmp    %r14d,%ebx
cmovl  %ebx,%r14d
jmp    1180 <main+0x40>
mov    $0x7fffffff,%r14d
imul   (%rsp),%r14d
lea    0xe3d(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = sdiv i32 %8, %9
store i32 %10, i32* %4
store i32 2147483647, i32* %6
store i32 1, i32* %5
br label %11
11: ; preds = %43, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = call i32 @sqrt(i32 %13)
%15 = icmp sle i32 %12, %14
br i1 %15, label %16, label %46
16: ; preds = %11
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = srem i32 %17, %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %16
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = sdiv i32 %23, %24
%26 = call i32 @gcd(i32 %22, i32 %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %42
28: ; preds = %21
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = sdiv i32 %30, %31
%33 = add nsw i32 %29, %32
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %42
36: ; preds = %28
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = load i32, i32* %5
%40 = sdiv i32 %38, %39
%41 = add nsw i32 %37, %40
store i32 %41, i32* %6
br label %42
42: ; preds = %36, %28, %21, %16
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %11
46: ; preds = %11
%47 = load i32, i32* %6
%48 = load i32, i32* %2
%49 = mul nsw i32 %47, %48
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %2
%7 = load i32, i32* %1
%8 = sdiv i32 %6, %7
%9 = call i32 @sqrt(i32 %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %29, label %11
11: ; preds = %0, %24
%12 = phi i32 [ %25, %24 ], [ 2147483647, %0 ]
%13 = phi i32 [ %26, %24 ], [ 1, %0 ]
%14 = srem i32 %8, %13
%15 = sdiv i32 %8, %13
%16 = icmp eq i32 %14, 0
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = call i32 @gcd(i32 %13, i32 %15)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = add nsw i32 %15, %13
%22 = icmp slt i32 %21, %12
%23 = select i1 %22, i32 %21, i32 %12
br label %24
24: ; preds = %20, %11, %17
%25 = phi i32 [ %12, %17 ], [ %12, %11 ], [ %23, %20 ]
%26 = add nuw nsw i32 %13, 1
%27 = call i32 @sqrt(i32 %8)
%28 = icmp slt i32 %13, %27
br i1 %28, label %11, label %29
29: ; preds = %24, %0
%30 = phi i32 [ 2147483647, %0 ], [ %25, %24 ]
%31 = load i32, i32* %1
%32 = mul nsw i32 %31, %30
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
ret i32 0
}