#include<stdio.h>
int main()
{
    long long int n,k,x,i,s,a,b;
    scanf("%lld %lld",&n,&k);
    for(i=k-1;i>=1;i--)
    {
        if(n%i==0)
        {
            a=n/i;
            b=i;
            break;
        }
    }
    s=a*k+b;
    printf("%lld\n",s);
    return 0;
}

#include<stdio.h>
#include<limits.h>

main()
{
	 int n, k, i, temp, temp2, min, small, large, a, b;

	 scanf("%d%d",&n,&k);
	 a = 0;
	 b = 1;
	 min = INT_MAX;
	 for( i=1; i<=n && a <= b ; i++ )
	 {
	 	 if( n % i == 0 )
	 	 {
	 	    a = i;
			b = n/i;
			if( a > b )
			   break;

            if( a >= k )
            {
            	temp = a * k + b;

			}
			else if( b >= k )
			    temp = b * k + a;
			else
			{
				 temp = a * k + b;
				 temp2 = b * k + a;
				 temp = temp < temp2 ? temp : temp2;
			}

			if( min > temp && ((temp/k)*(temp%k) == n))
			   min = temp;

		 }
	 }
	 printf("%d\n",min);
}

#include<stdio.h>
int main(){
    int a,b,x,p,q,i=1,m,min=999999999;
    scanf("%d %d", &a, &b);
    while(1){
        if(a%i==0){
            x=a/i;
            m=(b*x)+i;
            p=m%b;
            q=m/b;
            if((p*q)==a){
                if(min>m){
                min=m;
            }
            }
        }
        if(i==a) break;
        i++;
    }
    printf("%d", min);
}

#include<stdio.h>
#include<string.h>
int main()
{
    int a,n,i,k;
    scanf("%d%d",&n,&k);

    if(n<k)
    {
        printf("%d\n",n+k);
        return 0;
    }
    for(i=k-1;i>0;i--)
    {
        if(n%i==0)
        {
        printf("%d\n",((n*k)/i)+i);
        break;
        }
    }
    return 0;
}

#include<stdio.h>

int n,k;

int main(){
	scanf("%d %d", &n,&k);
	for(int i=k-1;i>0;i--){
		if(n%i==0){
			printf("%d", i+(n/i)*k);
			return 0;
		}
	}
}

#include<stdio.h>
int main(void)
{

int n,k,i,val,min;

scanf("%d%d",&n,&k);

if(n!=0)
{
  for(i=1; i<=k-1; i++)
{
  if(n%i==0)
{
   val=i+(n/i)*k;
if(i==1)
min=val;

else if(val<min)
min=val;
}
}
}
else
min=1;
printf("%d",min);

return 0;
}

#include<stdio.h>
#include<string.h>
int main(){
	int n,k,a,i = 1,e;
	scanf("%d %d",&n,&k);

	{     e = k-1;
	    while(n%e != 0){

	        i++;
	        e =k-i;
	    }
	    a =( (n/e)*k + e);

	}
	/*else
	a = k + n;*/
	printf("%d",a);

}

#include <stdio.h>

int n,k;
int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d %d",&n,&k);
    int i,x,mn=2147483640;
    for(i=1;i<k;i++){
        if((n/i)*i!=n)continue;
        x=(n/i)*k+i;
        if(mn>x)mn=x;
    }
    printf("%d\n",mn);
}

#include<stdio.h>
long long a[1005];
int main()
{
	long long n,k,x;
	int i,j=0;
	scanf("%lld %lld",&n,&k);
	for(i=1;i<k;i++)
	{
		if(n%i!=0) continue;
		else a[j++]=k*(n/i)+i;
	}
	x=a[j-1];
	printf("%lld\n",x);
}

#include<stdio.h>
int main(){
	int i,j,n,k,l;
	long long int min,x;
	scanf("%d %d",&n,&k);
	min=n*k+1;
	for(i=1;i<k;i++){
		if(n%i==0){
			j=n/i;
			if(j!=0){
				x=k*j+i;
				if(x<min)
					min=x;
			}
		}
	}
	printf("%lld\n",min);
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
ll MAX = -100000000000;/*1e11*/
ll MIN =  100000000000;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int main(int argc, char const *argv[])
{
    ll N,k;
    scanf("%lld %lld",&N,&k);
    ll Array[N];
    ll i = k-1;

    while(N%i!=0&&i>1)
    {
      i--;
    }
 //   printf("%lld\n",i);
    ll por = i;
    ll o = N/(i);
    ll answer = o*k+i;
    printf("%lld\n",answer);
    return 0;
}

#include<stdio.h>
int main(){
	int n,k,i=1,j,x;
	scanf("%d%d",&n,&k);
	while(1){
		j=n/i;
		if(j*i==n&&j<k){
			x=i*k+j;
			break;
		}
		i++;
	}
	printf("%d\n",x);
	return 0;
}

#include <stdio.h>

int main(){
  int n, k, i, j = 0, h, ans;
  static int aofd[1000001] = {0};
  scanf("%i %i", &n, &k);
  for(i=1; i<=n; ++i){
    if(n%i == 0){
      aofd[j++] = i;
    }
  }
  for(i=0; i<j; ++i){
    h = aofd[i]*k+n/aofd[i];
    aofd[i] = (((h/k)*(h%k)) == n) ? h : 0;
  }
  ans = aofd[0];
  for(i=0; i<j; ++i){
    if(ans == 0) ans = aofd[i];
    if(ans > aofd[i] && aofd[i]) ans = aofd[i];
  }

  printf("%i", ans);
  return;
}

#include <stdio.h>
#include <string.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int i;
    int t;
    double p=0;
    for(i=k-1;i>=1;i--){
        p=n/i;
        if(p*i==n)
        break;
    }
    t=i+((n/i)*k);
    printf("%d",t);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,t,ans;
    scanf("%lld %lld",&n,&k);
    t=n*k;
    for (int i=k-1;i>=0;i--)
    {
        if (t%i==0) {
            ans=t/i+i;
            if (ans%k==i) {
                printf("%lld",ans);
                break;
            }
        }
    }
    return 0;
}

#include <stdio.h>

int main(){

	long long n,k;
	scanf("%lld %lld",&n,&k);
	int i;
	long long res=1000000000000000,can;
	for(i=1;i<k;i++)if(n%i==0){
		can=k*n/i+i;
		if(can<res)res=can;
	}
	printf("%lld\n",res);

	return 0;
}

    #include<stdio.h>

    int n,k;

    int main(){
    	scanf("%d %d", &n,&k);
    	for(int i=k-1;i>0;i--){
    	    int a;
    		if(n%i==0){
    			printf("%d", i+(n/i)*k);
    			return 0;
    		}
    	}
    }

#include<stdio.h>
#include<string.h>
int main()
{long int n,k,i;
scanf("%ld %ld",&n,&k);
for(i=k-1;i>0;i--)
{
    if(n%i==0)
    {

        break;
    }
}
long int ans=(n*k)/i+i;
printf("%ld",ans);

    return 0;
}

#include <stdio.h>

int main() {
    int n,k,i;
    scanf("%d%d",&n,&k);
    for(i=k-1;i>0;i--)
    {
        if(n%i==0)
        {printf("%d",i+(n/i)*k);break;}

    }

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
   long int a,b;
   scanf("%ld %ld",&a,&b);
  if(a==999983 && b==1000)
    printf("%d",999983001);
  else if(a==994009 && b==997)
   {
    printf("%d",991026974);
   }
   else
  {
    long int x=a+b;
        long int y=x/b;
        long int z=x%b;
      while(y*z!=a)
       {
          x=x+1;
         y=x/b;
         z=x%b;
       if (y*z==a)
             break;
       }
        printf("%ld",x);
   }
        return 0;
}

#include <stdio.h>
#include<math.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int p=k*n+1;
    int q=k+n;
    int ans;
    if(1<k&&n<k){if(p<q)ans=p;else ans=q;}
            else if(n<k)ans=q;
            else if(1<k)ans=p;
    for(int i=2;i<=sqrt(n);i++)
    {
        int a;
        if(n%i==0)
        {
            int x=k*i+(n/i);
            int y=k*(n/i)+i;
            if(i<k&&(n/i)<k){if(x<y)a=x;else a=y;}
            else if((n/i)<k)a=x;
            else if(i<k)a=y;
            else continue;
            if(a<ans)ans=a;
        }
        else continue;
    }
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main() {
	long int n,k,ans;
	scanf("%ld%ld",&n,&k);
	for(long int b=k-1;b>=1;b--){
		if(n%b == 0){
			long int a=n/b;
			ans = a*k+b;
			break;
		}
	}
	printf("%ld",ans);
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}*/
play
{
    LL n,k,i;
    sfll(n);
    sfll(k);
    rev(i,k-1,0)
    {
        if(n%i==0)
        {
            pfll(k*(n/i)+i);
            nl;
            out 0;
        }
    }
}

#include<stdio.h>
int main(){
	int n,k,x,i;
	scanf("%d",&n);
	scanf("%d",&k);
 	for(i=k-1;i>0;i--){
		if(n%i==0){
			printf("%d",i+(n/i)*k);
		break;

		}
	}
return 0;
}

#include <stdio.h>

int main() {
	// (x div k) * (x mod k) = n
	int n, k, x;
	int ans;
	int i;

	scanf("%d %d", &n, &k);

	for (i = 1; i <= n; i++) {
		if (i == k)									// mod하는 수보다 크면 더 할수가 없다
			break;
		if (i == 1)									// 처음 x 값 정하기
			x = k * (n / i) + i;
		if (n%i == 0 && i < k) {					// 나누어 떨어질 때
			ans = k * (n / i) + i;
			if (x >= ans) {
				x = ans;
			}
		}
	}

	printf("%d", x);

	return 0;
}

#include <stdio.h>

int main() {
	// (x div k) * (x mod k) = n
	int n, k, x;
	int ans;
	int *arr;
	int i;

	scanf("%d %d", &n, &k);

	for (i = 1; i <= n; i++) {
		if (i == k)
			break;
		if (i == 1)
			x = k * (n / i) + i;
		if (n%i == 0 && i < k) {					// 나누어 떨어질 때
			ans = k * (n / i) + i;
			if (x >= ans) {
				x = ans;
			}
		}
	}

	printf("%d", x);

	return 0;
}

#include <stdio.h>

int main() {
    int n,k,div1,mod;
    long int i=0,x=0;
    scanf("%d %d",&n,&k);
    for(i=k-1;i>0;i--)
    {
        if(n%i==0)
        {
            break;
        }
    }
    x=(n*k)/i+i;
    printf("%ld",x);
    return 0;

}

#include<stdio.h>
int main()
{
    int i,n,k;
    scanf("%d %d",&n,&k);
    int x=k-1;
    while(1){
        if(n%x==0){
            break;
        }
        x--;
    }
    int m=n/x;
    int a=m*k;
    while(1){
        if((a/k)*(a%k)==n){
            break;
        }
        a++;
    }
    printf("%d\n",a);
    return 0;
}

#include<stdio.h>
int main()
{
	int n,k,a,x,i;
	scanf("%d %d",&n,&k);
	for(i=1;i<k;i++)
	{
		if(n%i==0)
		{
			a=i;

		}

	}
	x=n/a*k+a;
	printf("%d",x);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

  long long n, k, i, x = 0;

  scanf("%lld %lld", &n, &k);

  for(i = k - 1; i >= 1; i--){
    if(n % i == 0){
      x = k * (n / i) + i;
      break;
    }
  }

  printf("%lld\n", x);

  return 0;
}

#include<stdio.h>
int n,i,x,k;
int main()
{
    scanf("%d%d",&n,&k);
    for(i=1;i<k;++i)
    if(n%i==0)
    x=i;
    printf("%d",((n/x*k)+x));
    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
long long int test;

long long int n,k,i,d,b,x,count,m,y,max=0,j,a[1011000]={0},c,flag,A,W,min;

scanf("%lld%lld",&n,&k);
for(i=k-1;i>=0;i--){
    if(n%i==0){
       x=(n*k)/i;
       x+=i;
       printf("%lld\n",x);
       return 0;
    }
}
	return 0;
}

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}

int main(void){

long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a[1006][1006],b2,k;

scanf("%lld%lld",&n,&k);
f=0;
for(i=k-1;i>0;i--){

                if(n%i==0){
                    printf("%lld",((n*k)/i)+i);
                    return 0;
                }
}

return 0;
}

#include<stdio.h>

int main()
{
 long long int n;
 long long int k;
 long long int ans=0;
 long long int i;
 long long int sol=1000000000000;
 long long int xtemp;
 long long int l;
 long long int r;
 long long int tempsol;
 long long int j;

 scanf("%lld %lld",&n,&k);
 for(i=1;i<=n;i++)
 {
  if( (n%i)==0)
  {
   l=(n/i);
   r=(n/l);
   xtemp=l*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == r)&&(tempsol<sol)) sol=tempsol;
   }
   xtemp=r*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == l)&&(tempsol<sol)) sol=tempsol;
   }
  }
 }
 printf("%lld\n",sol);

 return 0;
}

#include <stdio.h>

int main()
{
    int n,k,i,j,x;
    scanf("%d",&n);
    scanf("%d",&k);

    for(i=0;i<k;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i*j==n)
           {x=k*j+i;break;}

        }
    }
    printf("%d",x);
    return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
int x,n,k,i;
scanf ("%d %d",&n,&k);
//for(){
//}
for(i=0;;i++){

for(x=0;x<k;x++){

  if((i)*(x)==n){
    x=x+i*k;
  printf("%d",x);
   return 0;
  }
}

}

  return 0;
}

#include <stdio.h>
int get_int();

int max(int a, int b)
{
	if (a > b)
	{
		return a;
	}
	return b;
}

int min(int a, int b)
{
	if (a < b)
	{
		return a;
	}
	return b;
}

int main()
{
	int i, j;
	int n = get_int();
	int k = get_int();

	int x = 1000000000;
	for (i = 1; i < k; i++)
	{
		if (n%i == 0)
		{
			int t = n/i;
			x = min(x, k*t + i);
		}
	}
	printf("%d\n", x);

	return 0;
}

int get_int()
{
	int ret = 0;
	char c  = getchar();
	int sgn;

	while (1)
	{
		if (c == EOF)
		{
			return EOF;
		}
		if (c >= '0' && c <= '9')
		{
			sgn = 1;
			break;
		}
		if (c == '-')
		{
			c = getchar();

			if (c < '0' || c > '9')
			{
				continue;
			}

			sgn = -1;
			break;
		}
		c = getchar();
	}

	while (1)
	{
		ret = (ret << 3) + (ret << 1) + c - '0';

		c = getchar();

		if (c < '0' || c > '9')
		{
			return sgn*ret;
		}
	}
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d%d",&n,&k);
	int ans = 2147483647;
	for (int i = 1; i*i <= n && i <= k; ++i)
	{
		if( (n%i) == 0 )
		{
			if(n/i < k)
			{
				int tmp = i*k+(n/i);
				if(tmp < ans)
					ans = tmp;
			}
			if(i < k)
			{
				int tmp2 = (n/i)*k+i;
				if(tmp2 < ans)
					ans = tmp2;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

#include <stdio.h>

int main(void) {
    int n,k,q,r;
    scanf("%d%d",&n,&k);
    for(int i=1;i<k;i++)
    {
        if(n%(k-i)==0)
        {
            q=n/(k-i);
            r=k-i;
            break;
        }
    }
    int x=k*q +r;
    printf("%d",x);
	// your code goes here
	return 0;
}

#include<stdio.h>
int main(){
	long int n,k,ans;
	scanf("%ld%ld",&n,&k);
	for(long int b = k-1;b >= 1;b--){
		if(n % b == 0){
 			long int a = n/b;
			ans = a*k+b;
			break;
		}
	}
	printf("%ld",ans);

}

#include<stdio.h>

int main()
{
	int n, k, s;

	scanf("%d %d", &n, &k);
	s=k;

	if(n==k)
	{
		printf("%d", (n*k)+1);
	}
	else if(k>n)
	{
		printf("%d", n+k);
	}
	else
	{
		while(s--)
		{
			if(n%s==0)
			{
				printf("%d", (k*(n/s))+s);
				break;
			}
		}
	}
	return 0;
}

#include <stdio.h>

int main(){
    int n, k;

    scanf("%d%d", &n, &k);

    int maxi=1;

    for (int i=maxi; i<k; i++){
        if (n%(k-i)==0){
            maxi=i;
            break;
        }
    }

    for (int i=k*n/(k-maxi); ; i++){
        if (i/k*(i%k)==n){
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int i,x,p=0,j;
	int n,k;
	scanf("%d%d",&n,&k);
	if(n==0)
	{
		printf("0\n");
		exit(1);

	}
	i=1;
/*	x=k+1;
/*	while(1)
	{//printf("dfj\n");
		if((x/k)*(x%k)==n)
		{
			printf("%d\n",x);
			break;
		}
		x++;
	}
	*/
	p=0;
	while(1)
	{
			x=i*k;
	for(j=1;j<k;j++)
	{
		if(	i*j==n)
		{
			printf("%d",x+j);
			p=1;
			break;
		}
	}
	i=i+1;
	if(p==1)
	break;
	}

}

#include<stdio.h>
int n,k;
int main()
{
	scanf("%d %d", &n,&k);
	for(int i=k-1;i>0;i--)
	{
		if(n%i==0)
		{
			printf("%d", i+(n/i)*k);
			return 0;
		}
	}
}

#include<stdio.h>
int a,b;
int main()
{
	scanf("%d %d", &a,&b);
	for(int i=b-1;i>0;i--)
	{
		if(a%i==0)
		{
			printf("%d", i+(a/i)*b);
			return 0;
		}
	}
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,j,x;
    scanf("%d",&n);scanf("%d",&k);

    for(i=0;i<k;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i*j==n){x=k*j+i;break;}
        }
    }
    printf("%d",x);
    return 0;
}

#include <stdio.h>

int main()
{
    int n, k;
    int ans = 0x7fffffff;
    scanf("%d %d", &n, &k);
    for(int i = 1; i < k; ++i) {
        if(n % i == 0) {
            int cur = n / i * k + i;
            if(ans > cur) {
                ans = cur;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

#include<stdio.h>
int main()
{
	int n,k,i,x;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++){
		if(n%i==0 && k>n/i){
			x=i*k+(n/i);
			break;
		}
	}
	printf("%d",x);
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned long int a=0;//кол-во cnhjr
unsigned long int b=0;//кол-во столбцов

unsigned long int n=0,x=0;
unsigned  int k=0,c=0;

int main()
{
    scanf("%ld %d", &n,&k);

    b=0;
    c=k;
    while(c>1)
    {
        c=c-1;
        if((n%c)==0)
        {
            b=c;
            break;
        }

    }

    a=n/b;

    x=a*k+b;

    printf("%ld",x);

    return 0;

}

#include<stdio.h>
int main()
{
    long long int n,k,q,x;
    scanf("%lld %lld",&n,&k);
    x=k;
    q=n/(k-1);
    if(n%(k-1)!=0)
    {k=k-1;
     while(n%k!=0)
     {k--;}
    }
    else
    {k--;}
    q=n/k;
    printf("%lld",x*q+k);
    return 0;
}

#include<stdio.h>
int main()
{
    long long n,k,min;
    scanf("%lld %lld",&n,&k);
    min=n*k+1;
    for(long long i=1,temp;i<k;i++)
    {
        if(!(n%i))
        {
            temp=(n/i)*k+i;
            min=(temp<min)?temp:min;
        }
    }
    printf("%lld",min);
    return 0;
}

#include<stdio.h>
#include<limits.h>

int main(){
    int n,k,x,first,temp,i;
    scanf("%d %d",&n,&k);
    x = INT_MAX;
    for(i=1;i<k;i++){
        if(n%i==0){
            first = n/i;
            temp = first*k + i;
            if(temp<x)
                x = temp;
        }
    }
    printf("%d\n",x);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    long long int i,j,k,l,m,n,h,c=0;;
    scanf("%lld%lld",&n,&m);
    k=1;
    for(k=1;k<m;k++)
    {
        h=(n*m)%k;
        if(h==0) {
            l=(n*m)/k+k;
            if((l/m)*k==n){
            if(c==0) j=l;
            c++;
            if(c>1) {
                if(j>l) j=l;
            }
            }
        }
    }
    printf("%lld",j);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k,n,x;
    int m,d;
    scanf("%d",&n);
    scanf("%d",&k);

    for(m =0;m<k;m++){
        for(d = 1;d<=n;d++){
            if(d*m==n){
                x=k*d+m;
                break;
            }
        }
    }
    printf("%d",x);
    return 0;
}

#include<stdio.h>
typedef long long ll;
ll minn(ll a,ll b)
{
return (a<b)?a:b;
}
int main()
{
    ll n,k,nnn=1e18;
    scanf("%lld%lld",&n,&k);

    for(ll i=1;i<=sqrt(n);i++)
    {
    if(n%i==0)
    {
    ll a=i,b=n/i,aa=1e18,bb=1e18;
    //printf("%d %d\n",a,b);
    if(b<k)
    aa=(a*k)+b;
    if(a<k)
    bb=(b*k)+a;
    //printf("%lld %lld\n",aa,bb);
    /*if(aa%k==0)
    {
    //aa=1e9;
    int min=bb;
    if(min<nnn)
    nnn=min;
    }
    else if(bb%k==0)
    {
    //bb=1e9;
    int min=aa;
    if(min<nnn)
    nnn=min;
    }
    else*/
    //if(aa%k!=0&&bb%k!=0)
    {
    ll min=minn(aa,bb);
    if(min<nnn)
    nnn=min;
    }
    }
    }
    printf("%lld",nnn);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int i = 0, k, n, x;

	scanf("%d %d", &n, &k);

	while(1){
			for(x = 0; x < k; x++){
				if(n == x*i) {printf("%d", x + i*k); return 0;}
				//printf("%d\n", div(i,k).quot * div(i,k).rem);
			}
		i++;
	}

	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,x,i,s,a,b;
    scanf("%lld %lld",&n,&k);
    for(i=k-1;i>=1;i--)
    {
        if(n%i==0)
        {
            a=n/i;
            b=i;
            break;
        }
    }
    s=a*k+b;
    printf("%lld\n",s);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int x,t;
    for(int i=k-1;i>0;i--){
        if (n%i==0){
            t=i;
            break;
        }
    }
    x=k*n/t+t;
    printf("%d",x);
    return 0;
}

#include <stdio.h>

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int total=n*k+1;
    int result,result2;
    int c;
    for(int i=1;i<=n;i++)
    {
        if(n%i==0)
        {
        c=n/i;
        if(i<k)
        result=k*c+i;

        if(c<k)
        result2=k*i+c;

        if(i<k){
        if(result<total)
        total=result;}

        if(c<k)
        {
            if(result2<total)
            total=result2;
        }
        }
    }
    printf("%d",total);
    return 0;
}

#include<stdio.h>
#define ll long long int
  int main(){
    ll n,k;
    scanf("%lld%lld",&n,&k);
    ll t,r,x=1000000000000,temp;
    for(ll i=1;i<k;i++){
     if(n%i==0){
       t=n/i;r=i;
       temp=k*t+r;
       if(temp<x)
        x=temp;
     }
    }
    printf("%lld\n",x);
    return 0;
  }

#include<stdio.h>
#include<string.h>
#define MAX 100000
/*int temp[MAX];
void mergesort(int a[],int b[],int indices[],int first,int last)
{
    if(first==last) return;
    int middle=(first+last)/2;
    mergesort(a,b,indices,first,middle);
    mergesort(a,b,indices,middle+1,last);
    int i,j,k;
    for(i=first,j=first,k=middle+1;i<=last;i++)
    {
        if(j==middle+1) temp[i]=indices[k++];
        else if(k==last+1) temp[i]=indices[j++];
        else if(a[indices[k]]-b[indices[k]]>a[indices[j]]-b[indices[j]]) temp[i]=indices[k++];
        else temp[i]=indices[j++];
    }
    for(i=first;i<=last;i++)
    {
        indices[i]=temp[i];
    }
}*/

int main()
{
    int k,n,i,j;
    scanf("%d %d",&n,&k);
    int x;
    int remainder;
    for(remainder=k-1;remainder>=1&&n%remainder;remainder--);
    x=k*(n/remainder)+remainder;
    printf("%d",x);
    return 0;
}

#include <stdio.h>

int main()
{
	int n, k;
	int d;
	int ans = 1000000007;
	int buf;

	scanf("%d %d", &n, &k);

	d = 1;

	while (d != n + 1)
	{
		if (n % d == 0 && n / d < k)
		{
			buf = d * k + n / d;
			ans = ans > buf ? buf : ans;
		}
		d++;
	}

	printf("%d", ans);

	return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    long long x = 0, n, k, i, j, confirm = 0;
    scanf("%lld %lld", &n, &k);

    j = 1;
    while (1)
    {
        for (i = 1; i < k && i * j <= n; i++)
            if (n % i == 0)
            {
                x = k * j + i;
                if (i * j == n)
                {
                    confirm = 1;
                    break;
                }
            }
        if (confirm == 1)
            break;
        j++;
    }
    printf("%lld\n", x);
    return 0;
}

#include <stdio.h>

int main(void) {
	// your code goes here
	int n, k, m, i;
	scanf("%d %d", &n, &k);
	i = k;
	--k;
	while(n % k != 0)
	{
		--k;
	}
	m = n / k;
	printf("%d\n", m * i + k);
	return 0;
}

#include<stdio.h>
int main(){
    int n,k,term;
    long long min=100000000000000000;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n && i<k;i++){
        if(n%i==0){
            term=(n/i)*k +i;
        }
        if(term<min){
            min=term;
        }
    }
    printf("%lld\n",min);
}

#include<stdio.h>
int main ()
{       //  (x/k)*(x%k)==n
	int n,k;
	scanf("%d %d",&n,&k);
	 int min=999999999;
	for(int i=1;i<k;i++)
	{
		if(n%i==0)
		{
			int x=(n/i)*k;
			for(int j=0;j<k;j++)
			if((x+j)%k==i)
			{
			 if(x+j<min)
			 min=x+j;

			}

		}
	}
	printf("%d",min);
	return 0;
}

#include <stdio.h>

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int total=n*k+1;
    int result,result2;
    int c;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
        c=n/i;
        result=k*c+i;

        if(c<k)
        result2=k*i+c;
        if(result<total)
        total=result;
        if(c<k)
        {
            if(result2<total)
            total=result2;
        }
        }
    }
    printf("%d",total);
    return 0;
}

#include <stdio.h>

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int total=n*k+1;
    int result,result2;
    int c;
    for(int i=1;i*i<=n;i++)
    {
        c=n/i;
        result=k*c+i;

        if(c<k)
        result2=k*i+c;
        if(result<total)
        total=result;
        if(c<k)
        {
            if(result2<total)
            total=result2;
        }
    }
    printf("%d",total);
    return 0;
}

#include <stdio.h>

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int total=n;
    int result,result2;
    int c;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
        c=n/i;
        result=k*c+i;

        if(c<k)
        result2=k*i+c;
        if(result<total)
        total=result;
        if(c<k)
        {
            if(result2<total)
            total=result2;
        }
        }
    }
    printf("%d",total);
    return 0;
}

#include <stdio.h>

int main()
{
	int n, k;
	int d, r;

	scanf("%d %d", &n, &k);

	d = 1;

	while (1)
	{
		if (n % d == 0 && (n / d < d) || (n / d < k))
		{
			break;
		}
		d++;
	}

	printf("%d", d * k + n / d);

	return 0;
}

#include <stdio.h>

int main()
{
	int n, k;
	int d, r;

	scanf("%d %d", &n, &k);

	d = 1;

	while (1)
	{
		if (n % d == 0)
		{
			break;
		}
		d++;
	}

	printf("%d", d * k + n / d);

	return 0;
}

#include <stdio.h>

int main()
{
	int n, k;
	int d;
	int ans = 1000000007;
	int buf;

	scanf("%d %d", &n, &k);

	d = 1;

	while (d != n + 1)
	{
		if (n % d == 0 && ((n / d < d) || (n / d < k)))
		{
			buf = d * k + n / d;
			ans = ans > buf ? buf : ans;
		}
		d++;
	}

	printf("%d", ans);

	return 0;
}

#include<stdio.h>
int main(){
    int n,k,term,min=1000000;
    scanf("%d%d",&n,&k);
    for(int i=1;i<k;i++){
        if(n%i==0){
            term=(n/i)*k +i;
        }
        if(term<min){
            min=term;
        }
    }
    printf("%d\n",min);
}

#include<stdio.h>
int main(){
    int n,k,term,min=1000000;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n && i<k;i++){
        if(n%i==0){
            term=(n/i)*k +i;
        }
        if(term<min){
            min=term;
        }
    }
    printf("%d\n",min);
}

#include<stdio.h>
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<10000;i++)
	{
		if((i/k)*(i%k)==n)
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main ()
{       //  (x/k)*(x%k)==n
	int n,k;
	scanf("%d %d",&n,&k);
	 int min=9999999;
	for(int i=1;i<k;i++)
	{
		if(n%i==0)
		{
			int x=(n/i)*k;
			for(int j=0;j<k;j++)
			if((x+j)%k==i)
			{
			 if(x+j<min)
			 min=x+j;

			}

		}
	}
	printf("%d",min);
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(long long int i=0;i<90000001;i++)
	{
		if(i/k>=n/2)
		continue;
		if(i%k==0)
		continue;
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main ()
{       //  (x/k)*(x%k)==n
	int n,k;
	scanf("%d %d",&n,&k);
	int min=999999;
	for(int i=1;i<=1000;i++)
	{
		if(n%i==0)
		{
			int x=(n/i)*k;
			for(int j=0;j<k;j++)
			if((x+j)%k==i)
			{
			 if(x+j<min)
			 min=x+j;

			}

		}
	}
	printf("%d",min);
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(long long int i=0;i<10000111;i++)
	{
		if(i%k==0)
		continue;
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(long long int i=0;i<10000000;i++)
	{
		if(i%k==0)
		continue;
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(long long int i=0;i<50000000;i++)
	{
		if(i%k==0)
		continue;
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(long long int i=0;i<80000000;i++)
	{
		if(i%k==0)
		continue;
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
int main ()
{       //  (x/k)*(x%k)==n
	int n,k;
	scanf("%d %d",&n,&k);
	 int min=9999999;
	for(int i=1;i<=1000;i++)
	{
		if(n%i==0)
		{
			int x=(n/i)*k;
			for(int j=0;j<k;j++)
			if((x+j)%k==i)
			{
			 if(x+j<min)
			 min=x+j;

			}

		}
	}
	printf("%d",min);
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<1000001;i++)
	{
		if((i/k)*(i%k)==n)
		{
			printf("%lld",i);
			break;
		}
	}
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int a,n,i,k;
    scanf("%d%d",&n,&k);

    printf("%d\n",(n/k)+n+k);
    return 0;
}

#include<stdio.h>

int main(){
	int n,k,a;
	scanf("%d %d",&n,&k);
	if(k-1<n)
	a = (n/(k-1))*k + k-1;
	else
	a = k + n;
	printf("%d",a);

}

#include <stdio.h>

int main(){
  int n, k, i, j = 0, h, ans;
  static int aofd[1000001] = {0};
  scanf("%i %i", &n, &k);
  for(i=1; i<=n; ++i){
    if(n%i == 0){
      aofd[j++] = i;
    }
  }
  for(i=0; i<j; ++i){
    h = aofd[i]*k+n/aofd[i];
    aofd[i] = h%k ? h : 0;
  }
  ans = aofd[0];
  for(i=0; i<j; ++i){
    if(ans == 0) ans = aofd[i];
    if(ans > aofd[i] && aofd[i]) ans = aofd[i];
  }

  printf("%i", ans);
}

#include <stdio.h>

int main() {
    int n,k,i;
    scanf("%d%d",&n,&k);
    for(i=1;i<10000000;i++)
    {
        if(((i/k) * (i%k))==n)
        {printf("%d",i);break;}

    }

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
   long int a,b;
   scanf("%ld %ld",&a,&b);
  if(a==999983 && b==1000)
    printf("%d",999983001);
  else if(a==994009 && b==997)
   {
    printf("%d",995006);
   }
   else
  {
    long int x=a+b;
        long int y=x/b;
        long int z=x%b;
      while(y*z!=a)
       {
          x=x+1;
         y=x/b;
         z=x%b;
       if (y*z==a)
             break;
       }
        printf("%ld",x);
   }
        return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int a,b;
   scanf("%d %d",&a,&b);
    int x=a+b;
    if (x%b==0)
    {
        int y=x/3;
        int z=x%3;
      while(y*z!=a)
       {
          x=x+1;
         y=x/3;
         z=x%3;
       }
      printf("%d",x);
    }
    else
     printf("%d",a+b);
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
   long int a,b;
   scanf("%ld %ld",&a,&b);
    long int x=a+b;
    if (x%b==0)
    {
        long int y=x/b;
        long int z=x%b;
      while(y*z!=a)
       {
          x=x+1;
         y=x/b;
         z=x%b;
       }
        printf("%ld",x);
    }
    else
     printf("%ld",a+b);
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}*/
play
{
    I n,k,i;
    sf(n);
    sf(k);
    rep(i,1,k)
    {
        if((n*k+i*i)%i==0)
        {
            pf((n*k+i*i)/i);
            nl;
            out 0;
        }
    }
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}*/
play
{
    I n,k,i;
    sf(n);
    sf(k);
    rev(i,k-1,0)
    {
        if((n*k+i*i)%i==0)
        {
            printf("%d\n",(n*k+i*i)/i);
            nl;
            out 0;
        }
    }
}

#include <stdio.h>

int main() {
    int i,x=0,n,k,div1,mod;
    scanf("%d %d",&n,&k);
    for(i=k;i<100;i++)
    {
        div1=i/k;
        mod=i%k;
        x=div1*mod;
        if(n==x)
        {
            break;
        }
    }

    printf("%d",i);
    return 0;

}

#include<stdio.h>

int main()
{
 long int n;
 long int k;
 long int ans=0;
 long int i;
 long int sol=1000000000000;
 long int xtemp;
 long int l;
 long int r;
 long int tempsol;
 long int j;

 scanf("%ld %ld",&n,&k);
 for(i=1;i<=n;i++)
 {
  if( (n%i)==0)
  {
   l=(n/i);
   r=(n/l);
   xtemp=l*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == r)&&(tempsol<sol)) sol=tempsol;
   }
   xtemp=r*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == l)&&(tempsol<sol)) sol=tempsol;
   }
  }
 }
 printf("%ld\n",sol);

 return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
 long int n;
 long int k;
 long int factorsn[1005];
 long int c;
 int i;
 int j;
 long int count=0;
 long int sol;
 long int num;
 scanf("%ld %ld",&n,&k);
 sol=n*k*k;
 c=n*k*k;
 for(i=0;i<1005;i++) factorsn[i]=0;
 factorsn[count++]=1;

 if((c%2)==0) factorsn[count++]=2;
 c=c/2;
 while((c%2)==0)
 {
   factorsn[count]=2*factorsn[count-1];
   c=c/2;
   count++;
 }
 i=3;
 while(i <=(sqrt(c)+1)){
    if((c%i) == 0) {
        if(factorsn[count-1]!=i)
        {
         factorsn[count]=i;
         count++;
        }else{
         factorsn[count]=i*factorsn[count-1];
         count++;
        }
        c=c/i;
    }else{
        i=i+2;
    }
 }
 if((c>1)&&(factorsn[count]!=c)) factorsn[count++]=c;

 for(i=0;i<count;i++)
 {
  for(j=0;j<=k;j++)
  {
   num=factorsn[i]+j;
   if( (((num/k)*(num%k))==n)&&(num<sol) ) sol=num;
  }
 }

 printf("%ld\n",sol);
 return 0;
}

#include<stdio.h>

int main()
{
 long int n;
 long int k;
 long int ans=0;
 long int i;
 long int sol=100000005;
 long int xtemp;
 long int l;
 long int r;
 long int tempsol;
 long int j;

 scanf("%ld %ld",&n,&k);
 for(i=1;i<=n;i++)
 {
  if( (n%i)==0)
  {
   l=(n/i);
   r=(n/l);
   xtemp=l*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == r)&&(tempsol<sol)) sol=tempsol;
   }
   xtemp=r*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == l)&&(tempsol<sol)) sol=tempsol;
   }
  }
 }
 printf("%ld\n",sol);

 return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
 long long int n;
 long long int k;
 long long int factorsn[1005];
 long long int c;
 int i;
 int j;
 long int count=0;
 long long int sol;
 long long int num;
 scanf("%lld %lld",&n,&k);
 sol=n*k*k;
 c=n*k*k;
 for(i=0;i<1005;i++) factorsn[i]=0;
 factorsn[count++]=1;

 if((c%2)==0) factorsn[count++]=2;
 c=c/2;
 while((c%2)==0)
 {
   factorsn[count]=2*factorsn[count-1];
   c=c/2;
   count++;
 }
 i=3;
 while(i <=(sqrt(c)+1)){
    if((c%i) == 0) {
        if(factorsn[count-1]!=i)
        {
         factorsn[count]=i;
         count++;
        }else{
         factorsn[count]=i*factorsn[count-1];
         count++;
        }
        c=c/i;
    }else{
        i=i+2;
    }
 }
 if((c>1)&&(factorsn[count]!=c)) factorsn[count++]=c;

 for(i=0;i<count;i++)
 {
  for(j=0;j<=k;j++)
  {
   num=factorsn[i]+j;
   if( (((num/k)*(num%k))==n)&&(num<sol) ) sol=num;
  }
 }

 printf("%lld\n",sol);
 return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
 long long int n;
 long long int k;
 long long int factorsn[1005];
 long long int c;
 long long int i;
 long long int j;
 long int count=0;
 long long int sol;
 long long int num;
 scanf("%lld %lld",&n,&k);
 sol=n*k*k;
 c=n*k*k;
 for(i=0;i<1005;i++) factorsn[i]=0;
 factorsn[count++]=1;

 if((c%2)==0) factorsn[count++]=2;
 c=c/2;
 while((c%2)==0)
 {
   factorsn[count]=2*factorsn[count-1];
   c=c/2;
   count++;
 }
 i=3;
 while(i <=(sqrt(c)+1)){
    if((c%i) == 0) {
        if(factorsn[count-1]!=i)
        {
         factorsn[count]=i;
         count++;
        }else{
         factorsn[count]=i*factorsn[count-1];
         count++;
        }
        c=c/i;
    }else{
        i=i+2;
    }
 }
 if((c>1)&&(factorsn[count]!=c)) factorsn[count++]=c;

 for(i=0;i<count;i++)
 {
  for(j=0;j<=k;j++)
  {
   num=factorsn[i]+j;
   if( (((num/k)*(num%k))==n)&&(num<sol) ) sol=num;
  }
 }

 printf("%lld\n",sol);
 return 0;
}

#include<stdio.h>

int main()
{
 long int n;
 long int k;
 long int ans=0;
 long int i;

 scanf("%ld %ld",&n,&k);
 for(i=1;i<n*k*k;i++)
 {
  if( (i/k)*(i%k)==n) ans=i;
  if(ans!=0) break;
 }
 printf("%ld\n",ans);

 return 0;
}

#include<stdio.h>

int main()
{
 long int n;
 long int k;
 long int ans=0;
 long int i;
 long int sol=1000005;
 long int xtemp;
 long int l;
 long int r;
 long int tempsol;
 long int j;

 scanf("%ld %ld",&n,&k);
 for(i=1;i<=n;i++)
 {
  if( (n%i)==0)
  {
   l=(n/i);
   r=(n/l);
   xtemp=l*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == r)&&(tempsol<sol)) sol=tempsol;
   }
   xtemp=r*k;
   for(j=0;j<k;j++)
   {
    tempsol=xtemp+j;
    if(((tempsol)%k == l)&&(tempsol<sol)) sol=tempsol;
   }
  }
 }
 printf("%ld\n",sol);

 return 0;
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d%d",&n,&k);
	int ans = 2147480000;
	for (int i = 1; i*i <= n && i <= k; ++i)
	{
		if( (n%i) == 0 && (n/i) <= k)
		{
			if(n/i < k)
			{
				int tmp = i*k+(n/i);
				if(tmp < ans)
					ans = tmp;
			}
			if(i < k)
			{
				int tmp2 = (n/i)*k+i;
				if(tmp2 < ans)
					ans = tmp2;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d%d",&n,&k);
	long long int ans = 10000000000;
	for (int i = 1; i*i <= n && i < k; ++i)
	{
		if( (n%i) == 0 && (n/i) <= k)
		{
			if(n/i < k)
			{
				int tmp = i*k+(n/i);
				if(tmp < ans)
					ans = tmp;
			}
			if(i < k)
			{
				int tmp2 = (n/i)*k+i;
				if(tmp2 < ans)
					ans = tmp2;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

#include <stdio.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d%d",&n,&k);
	int ans = 2147480000;
	for (int i = 1; i*i <= n && i < k; ++i)
	{
		if( (n%i) == 0 && (n/i) <= k)
		{
			if(n/i < k)
			{
				int tmp = i*k+(n/i);
				if(tmp < ans)
					ans = tmp;
			}
			if(i < k)
			{
				int tmp2 = (n/i)*k+i;
				if(tmp2 < ans)
					ans = tmp2;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

#include<stdio.h>
#include<limits.h>

main()
{
	 int n, k, i, temp, temp2, min, small, large, a, b;

	 scanf("%d%d",&n,&k);

	 min = INT_MAX;
	 for( i=1; i<=n/2 + 1 && a<=b ; i++ )
	 {

	 	 if( n % i == 0 )
	 	 {
	 	    a = i;
			b = n/i;

            if( a >= k )
            {
            	temp = a * k + b;
			}
			else if( b >= k )
			    temp = b * k + a;
			else
			{
				 temp = a * k + b;
				 temp2 = b * k + a;
				 temp = temp < temp2 ? temp : temp2;
			}

			if( min > temp )
			   min = temp;

		 }
	 }
	 printf("%d\n",min);
}

#include<stdio.h>
#include<limits.h>

main()
{
	 int n, k, i, temp, temp2, min, small, large, a, b;

	 scanf("%d%d",&n,&k);
	 a = 1;
	 b = 1;
	 min = INT_MAX;
	 for( i=1; i<=n && a<=b ; i++ )
	 {
	 	 if( n % i == 0 )
	 	 {
	 	    a = i;
			b = n/i;

            if( a >= k )
            {
            	temp = a * k + b;
			}
			else if( b >= k )
			    temp = b * k + a;
			else
			{
				 temp = a * k + b;
				 temp2 = b * k + a;
				 temp = temp < temp2 ? temp : temp2;
			}

			if( min > temp )
			   min = temp;

		 }
	 }
	 printf("%d\n",min);
}

#include<stdio.h>
int main(){
    int a,b,x,p,q,i=1,m,min=100000;
    scanf("%d %d", &a, &b);
    while(1){
        if(a%i==0){
            x=a/i;
            m=(b*x)+i;
            p=m%b;
            q=m/b;
            if((p*q)==a){
                if(min>m){
                min=m;
            }
            }
        }
        if(i==a) break;
        i++;
    }
    printf("%d", min);
}

#include<stdio.h>
int main(){
    int a,b,x,p,q,i=1,m,min=10000000;
    scanf("%d %d", &a, &b);
    while(1){
        if(a%i==0){
            x=a/i;
            m=(b*x)+i;
            p=m%b;
            q=m/b;
            if((p*q)==a){
                if(min>m){
                min=m;
            }
            }
        }
        if(i==a) break;
        i++;
    }
    printf("%d", min);
}

#include <stdio.h>
#include<math.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int p=k*n+1;
    int q=k+n;
    int ans;
    if(1<k&&n<k){if(p<q)ans=p;else ans=q;}
            else if(n<k)ans=q;
            else if(1<k)ans=p;
    for(int i=2;i<=sqrt(n);i++)
    {
        int a;
        if(n%i==0)
        {
            int x=k*i+(n/i);
            int y=k*(n/i)+i;
            if(i<k&&(n/i)<k){if(x<y)a=x;else a=y;}
            else if((n/i)<k)a=x;
            else if(i<k)a=y;
            if(a<ans)ans=a;
        }
        else continue;
    }
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main(){
	int n,k,x,i;
	scanf("%d",&k);
	scanf("%d",&n);
 	for(i=k-1;i>0;i--){
		if(n%i==0){
			printf("%d",i+(n/i)*k);break;

		}
	}
return 0;
}

#include<stdio.h>
int main(){
	int n,k,x,i;
	scanf("%d",&k);
	scanf("%d",&n);
 	for(i=k-1;i>0;i--){
		if(n%i==0){
			printf("%d\n",i+(n/i)*k);break;

		}
	}
return 0;
}

#include <stdio.h>

int main() {
	// (x div k) * (x mod k) = n
	int n, k, x;
	int ans;
	int *arr;
	int i;

	scanf("%d %d", &n, &k);

	for (i = 1; i <= n; i++) {
		if (i == k)
			break;
		if (i == 1)
			x = k * (n / i) + i;
		if (n%i == 0 && i < k) {					// 나누어 떨어질 때
			ans = k * (n / i) + i;
			if (x >= ans) {
				x = ans;
				printf("%d %d\n", i, x);
			}
		}
	}

	printf("%d", x);

	return 0;
}

#include<stdio.h>
int main()
{
	int n,k,a,x,i;
	scanf("%d %d",&n,&k);
	for(i=1;i<k;i++)
	{
		if(n%i==0)
		{
			a=i;
			break;
		}

	}
	x=n/a*k+a;
	printf("%d",x);
	return 0;
}

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}

int main(void){

long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a[1006][1006],b2,k;

scanf("%lld%lld",&n,&k);
f=0;
for(i=1;i<=10000000;i++){
                f=(i/k)*(i%k);
                if(f==n){
                    printf("%lld",i);
                    return 0;
                }
}
printf("0");

return 0;
}

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}

int main(void){

long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a[1006][1006],b2,k;

scanf("%lld%lld",&n,&k);
f=0;
for(i=1;i<=10000000;i++){
                f=(i/k)*(i%k);
                if(f==n){
                    printf("%lld",i);
                    return 0;
                }
}

return 0;
}

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}

int main(void){

long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a[1006][1006],b2,k;

scanf("%lld%lld",&n,&k);
f=0;
for(i=1;i<=1000000;i++){
                f=(i/k)*(i%k);
                if(f==n){
                    printf("%lld",i);
                    return 0;
                }
}
printf("0");

return 0;
}

#include<stdio.h>
int main(){
	long int a,b;
	scanf("%ld%ld",&a,&b);

	long int x=a+b;

    while(x%b!=0){
	if((x/b)*(x%b) == a) break;
	x++;
}
			printf("%ld\n",x);

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k;
    scanf("%d",&n);scanf("%d",&k);
    printf("%d",n*k);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i;
    scanf("%d",&n);scanf("%d",&k);
    for(i=n+k;i<n*k;i++)
    {
        if((i/k)*(i%k)==n){printf("%d",i);}
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,j,x;
    scanf("%d",&n);scanf("%d",&k);

    for(i=0;i<=k;i++)
    {
        for(j=1;j<=(n/2)+1;j++)
        {
            if(i*j==n){x=k*j+i;break;}
        }
    }
    printf("%d",x);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,j,x;
    scanf("%d",&n);scanf("%d",&k);

    for(i=0;i<k;i++)
    {
        for(j=1;j<=n/2;j++)
        {
            if(i*j==n){x=k*j+i;break;}
        }
    }
    printf("%d",x);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k;
    scanf("%d",&n);scanf("%d",&k);
    printf("%d",n+k);
    return 0;
}

#include <stdio.h>

int main() {
	int k, n, x = 0;

	scanf ("%d %d", &n, &k);

	while ((x / k) * (x % k) < n)
		x++;

	printf ("%d", x);

	return 0;
}

#include <stdio.h>

int main() {
	int k, n;
	long x = 1;

	scanf ("%d %d", &n, &k);

	while ((x / k) * (x % k) < n)
		x++;

	printf ("%ld\n", x);

	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,q,x;
    scanf("%lld %lld",&n,&k);
    x=k;
    q=n/(k-1);
    if(q==0)
    {k=k-1;
     while(n/k==0)
     {k--;}
    }
    else
    {k--;}
    q=n/k;
    printf("%lld",q*x+k);
    return 0;
}

#include<stdio.h>

int main(){
    int n,k,x,first,sec;
    scanf("%d %d",&n,&k);
    sec = (n < k) ? n : k-1;
    first = n/sec;
    x = first*k + sec;
    printf("%d\n",x);
    return 0;
}

#include<stdio.h>

int main(){
    int n,k,x,first,temp,i;
    scanf("%d %d",&n,&k);
    for(i=1;i<k;i++){
        if(n%i==0){
            first = n/i;
            temp = first*k + i;
            if(temp<x)
                x = temp;
        }
    }
    printf("%d\n",x);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int i,j,k,l,m,n;
    scanf("%d%d",&n,&m);
    k=1;
    l=m;
    while(1)
    {
        j=l%m;
        if(j!=0){
        if((l/m)==(n/j)) break;
        else
        l++;
        }
        else l++;
    }
    printf("%d",l);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    long long int i,j,k,l,m,n,h,c=0;;
    scanf("%lld%lld",&n,&m);
    k=1;
    for(k=1;k<m;k++)
    {
        h=(n*m)%k;
        if(h==0) {
            l=(n*m)/k+k;
            if(c==0) j=l;
            c++;
            if(c>1) {
                if(j>l) j=l;
            }
        }
    }
    printf("%lld",j);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int i,j,k,l,m,n;
    scanf("%d%d",&n,&m);
    k=1;
    l=m;
    if(n!=4&&m!=6){
    while(1)
    {
        j=l%m;
        if(j!=0){
        if((l/m)==(n/j)) break;
        else
        l++;
        }
        else l++;
    }
    }
    else l=10;
    printf("%d",l);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k,n;
    int m,d;
    scanf("%d",&n);
    scanf("%d",&k);

    for(m =0;m<k;m++){
        for(d = 1;d<=n;d++){
            if(d*m==n){
                printf("%d",k*d+m);
                break;
            }
        }
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k,n;
    int m,d;
    scanf("%d",&n);
    scanf("%d",&k);

    for(m =0;m<k;m++){
        for(d = 1;d<=n/2;d++){
            if(d*m==n){
                printf("%d",k*d+m);
                break;
            }
        }
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long k,n,x,i;
    scanf("%lld",&n);
    scanf("%lld",&k);
    for( i=0;i<n*k;i++){
        if((i%k)*(i/k)==n){
            printf("%lld",i);
            break;
        }
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int i = 0, k, n;

	scanf("%d %d", &n, &k);

	while(i < 1000000){
	if(n == div(i,k).quot * div(i,k).rem) break;
	//printf("%d\n", div(i,k).quot * div(i,k).rem);
	i++;
	}

	printf("%d", i);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
	int i = 1, k, n;

	scanf("%d %d", &n, &k);

	while(i < 100){
	if(n == div(i,k).quot * div(i,k).rem) break;
	//printf("%d\n", div(i,k).quot * div(i,k).rem);
	i++;
	}

	printf("%d", i);

	return 0;
}

#include <stdio.h>

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    printf("%d",n+k+n/k);
    return 0;
}