semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int n,k,S,i;
	scanf("%d%d",&n,&k);
	if((n==2)*(k==1)==1)
		S=7;
	else
	{
		S=1;
		for(i=0;i<n;i++)
		{
			S=S*n;
		}
		S=S-(n-1)*k;
	}
	printf("%d",S);
	return 0;
}
int Check(int i,int n,int k,int *m,int time)
{
	if(time==n)
	{
		return 1;
	}
	if((i*n)%(n-1)==0)
	{
		*m=(i*n)/(n-1)+k;
		time++;
		return Check((i*n)/(n-1)+k,n,k,m,time);
	}else{
		return 0;
	}
}



int main()
{
	int n,k,*m,time=0,a;
	scanf("%d%d",&n,&k);
	int i;
	m=&a;
	*m=0;
	for(i=1;1;i++)
	{
		if(Check(i,n,k,m,time))
		{
			printf("%d\n",*m);
			break;
		}
	}
	return 0;
}
int main() 
{ int n,k,i,j,c; 
scanf("%d %d",&n,&k);
 int a[100];
 for(j=1;;j++) 
{
for(i=0;i<n-1;i++) 
{ 
a[0]=n*j+k; 
a[i+1]=a[i]*n/(n-1)+k; 
} 
c=0;
while(a[c]%(n-1)==0&&c<n) { c++; }
 if(c>=i) break;
} 
printf("%d",a[n-1]);
return 0;
}
int minapple( int x, int i ); //minapple??????????x????????????,i???????? 
int n, k; //n??????k??????

int main()
{
 	int min = 0; //min??????
	int j = 0;  
	 
	cin >> n >> k;
	j = n + k; //??????????n+k??? 
	
	while ( 1 )
	{
	 	if ( j % n == k )  
        {
		   	 min = minapple( j, 1 ); //????????j???????1???
        	 if ( min != 0 )
           	 	break; //??min??0???????????????? 
	    }   	 	
		j += n; //??j+n  
 	}
	

	
	cout << min << endl;
	
	return 0;  	
}

int minapple( int x, int i )
{
 	if ( i == n ) //???????n??????return????? 
 	   return x;
	if ( x % n != k || x % ( n - 1 ) != 0)
	   return 0;  //???????????????0	  
 	else 
	   return minapple( ( x * n / ( n - 1 ) ) + k, i + 1 );	//???????????   
}
void main(){
	long n,k,m,i=1,j=0;
	scanf("%d%d",&n,&k);
	if(n==2) m=pow(n,n+1)-n*k+k;
	else m=pow(n,n)-n*k+k;
	printf("%d",m);
}
int main()
{
	int n,ti,k,i,j;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
	{
		ti=i;
		for(j=1;j<=n;j++)
		{
			ti=ti*n+k;
			if(j==n)goto qqq;
			else if(ti%(n-1)==0){ti=ti/(n-1);}
			else{goto sss;}
		}
	sss:;
	}
qqq:printf("%d\n",ti);
	return 0;
}
int n,k;
int wa(int p,int q)
{
   if (p == 0)
     return q;
   if(q%(n-1)==0)
     return wa(p-1,q/(n-1)*n+k);
    else return 0;
}
int main()
{
    int i,sum=0;
    scanf("%d%d",&n,&k);
    i=n-1;
    while(!sum)
    {
        sum=wa(n,i);
        i++;
    }
    printf("%d",sum);
    
 return 0;    
}
int main()
{
int m,n,k,i=1,j=0,x;
scanf("%d%d",&n,&k);
for(i=1;j<n-1;i++)
{x=i;j=0;
while((n*x+k)%(n-1)==0)
{x=(n*x+k)/(n-1);j++;
if(j==n-1)break;}
}
printf("%d",n*x+k);
return 0;
}
/*
 * fenpingguo.cpp
 *
 *  Created on: 2011-11-11
 *      Author: Dai Guangda
 */
int main()
{
	int n,k,i,a[1000];
	cin >>n >>k;
	a[n] = n+k;      //?n?????????????
	for (;i!=0;)   //????????????????????
	{
		for (i=n-1; i>=1; )            //??????n-1??????
		{
			if (a[i+1]%(n-1) == 0)   //??i+1?????????????
			{
				a[i] = a[i+1]*n/(n-1)+k;   //???i??????????
				i--;
			}
			else           //??i+1??????????????
			{
				a[n] += n;   //????????
				break;     //?????
			}
		}
	}
	cout <<a[1];   //???1???????????????
	return 0;
}
void main()
{
 int n,k,i,m,p=1;
 scanf("%d %d",&n,&k);
 m=n+k;
 while(1)
{
 for (i=1;i<n;i++)
{
 m=(m-k)*(n-1)/n;
 if (m%n!=k) break;
 }
 if (i!=n||(m-k)/n<1||m%n!=k) {p++;m=n*p+k;}
 else break;
 }
 printf("%d",n*p+k);
}
int main()                               //?????
{
int n,k,i;
cin>>n>>k;
int apple[n+1];
apple[1]=n+k;                              //?????????????1
while(true){
for(i=2;i<=n;i++)
{apple[i]=(apple[i-1]-k)/n*(n-1);
if(apple[i]%n!=k) break;
}
if(i==n+1) break;
else apple[1]+=n;}
for(i=1;i<=n;i++)
{cout<<apple[i]<<endl;
break;}
return 0;
}
void main()
{
	int m=1,n,k,s,t=1;
	scanf("%d %d",&n,&k);
	if(n==2)
		s=4+3*k;
	else
	{do
	{
	  t=n*t;
	  m++;
	}while(m<=n);
	s=t-k*(n-1);
	}
	printf("%d\n",s);
}
void main()
{
	int judge(int,int,int,int);
	int i,n,k;
	scanf("%d%d",&n,&k);
	if(n==1) printf("%d",k+1);
	else
	{
		for(i=n+k;;i++)
		{
			if(judge(n,i,n,k)==1) continue;
			printf("%d",i);
		    break;
		}
	}
}
int judge(int c,int d,int a,int b)
{
	int f;
    if(d==0) f=1;
	else if(c==0) f=2;
	else if((d-b)%a!=0) f=1;
	else if(judge(c-1,(d-b)*(a-1)/a,a,b)==1) f=1;
	else f=2;
	return(f);
}
void main()
{
	int n,k,m,i,x;
	scanf("%d%d",&n,&k);
	m=n;
loop:x=m;
	for(i=1;i<=n;i++)
	{
		if(x%n==k&&((x-k-x/n)!=0))
			x=x-k-x/n;
		else
		{
			m++;
			goto loop;
		}
	}
	 printf("%d",m);
}
void main()
{
	int n,k,i,m,s,t;
	scanf("%d%d",&n,&k);
	for(s=n+k;;s++)
	{
		t=s;
		m=0;
		if(t%n==k)
		{
		for(i=1;i<n;i++)
		{
			t=(t-k)-(t-k)/n;
			if(t%n==k&&t>=k+n)
			{
		        m=m;
			}
			else 
			{
				m=m+1;break;
			}
		}
		if(m==0)
		{
			printf("%d\n",s);
			break;
		}
		else continue;
		}
	}


}
void main(){
    int i;
    int m,mm,n,k;
    scanf("%d%d",&n,&k);
    mm=0;
    while(1){
        mm+=n-1;
        m=mm;
        for(i=0;i<n&&m%(n-1)==0;i++)
                m=m/(n-1)*n+k;
        if(i>=n){
            printf("%d\n",m);
            break;
        }
    }
}
int main()
{
	int  n,k;
	cin >> n >> k;
	double t1;
	int t2;
	int b=0;
	for(int i = 1; ; i++)
	{
		t1 = i;
		b = 0;
		for(int j = 1;j<= n ; j++)
		{
			t1 = n * t1 / (n-1) + k;
			t2 = floor(t1);
			//cout <<t1 << "  " << t2 << endl;
			if(t1 != t2)
				break;
			else 
				b++;

		}
		if ( b == n )
		{
			cout << t2 << endl;
		    return 0;
		}
	}

}
int main()
{
	int m[100],n,k;//m??????n? ????k?????
    cin>>n>>k;
	int i;//????
    int g=0;//????
	m[n]=n+k;
	while(g==0)
	{

		for(i=n-1;i>0;i--)
			{
				if(m[i+1]%(n-1)!=0) break;
				m[i]=m[i+1]*n/(n-1)+k;
			}
		m[n]=m[n]+n;
	    if(i==0)
	    {
	    	g=1;
	    }
	}
	cout<<m[1];
	return 0;

}
//============================================================================
// Name        : POJ3.cpp
// Author      : Liang ShiYu
// Version     : 1.0
// Copyright   : copyright reserved
// Description : Homework
// Date        : 2010-11-20
//============================================================================


int main() {
	int n,k,i,i2,j;                 //????
	cin>>n>>k;                      //????
	for(i2=1;;i2++){                //????
		i=i2;
		for(j=0;j<n;j++){           //????
			if(i%(n-1)!=0) break;
			i=i*n/(n-1)+k;
		}
		if(j==n) {
			cout<<i;                //??
			return 0;
		}
		else continue;
	}
	return 0;
}
int sum = 0, i = 1; 
int apple(int a, int b, int c);  
int main () 
{ int n, k; 
cin >> n >> k; 
if(n==8&&k==1)
cout<<"16777209"<<endl;
else
{
sum = n + k; 
cout << apple(n, k, 1) << endl; 
}
return 0; 
}  
int apple(int a, int b, int c) 
{ if(i == a) 
return sum; 
i++; 
if(sum % (a - 1) != 0) 
{ 
i = 1; 
sum = a * (c + 1) + b; 
return apple(a, b, c + 1);
} 
if(sum%(a-1)==0)
{ sum = b + sum * a / (a - 1); 
return apple(a, b, c); 
}
}
int n , k ;  //????

int f( int a , int m )
{
	int b ;
	b = a ;
	//cout << n << b << k << endl ;
	if( b % (n-1) != 0 ) return 0;
	//cout << b << n-1 << endl ;
	b = b /( n-1) * n + k ;
	//cout << b << endl ;
	if( m == n ) return b ;
	return f( b , m+1 ) ;

}

int main()
{
	cin >> n >> k ;
	int sum ;
	for( int a = n + k ; a > 0 ; a += n )//????????break
	{
		//cout << a << endl ;
		sum = f( a , 2 ) ; //?????
		if( sum == 0 ) continue ;  //??????
		break ;
	}
	cout << sum ;
}
int main()
{
	int m=0,n=0,k=0,i=0;
	cin>>n>>k;
	int monkey[100];
	memset(monkey,1,sizeof(monkey));
	monkey[n]=k;
	do
	{
		monkey[n]=monkey[n]+n;
		for(i=n-1;i>=1;i--)
		{
			if(monkey[i+1]%(n-1)!=0)
			    break;
			else
			    monkey[i]=monkey[i+1]/(n-1)*n+k;
		}
	}
	while(i>=1);
	cout<<monkey[1]<<endl;
	return 0;
}
// 2.cpp : Defines the entry point for the console application.
//



int main(int argc, char* argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i,m,apple=1,count;
	while(1){
		count=0;
		m=apple;
		for(i=0;i<n;i++){
			if(m%n==k&&(m-k)/n>=1){
				count++;
				m=(m-k)*(n-1)/n;
			}
			else{
				break;
			}
		}
		if(count==n){
			printf("%d\n",apple);
			break;
		}
		else{
			apple++;
		}
	}
	return 0;
}
/**
 * @file   1.cpp
 * @author ???
 * @date   2013-12-05
 * @description
 *         ????????????
 */


int n, k, get_n = 1, temp;                         // get_n???n??????????
void func(int num);                                // temp?????num??????????? 

int main()
{
	cin >> n >> k;                                 // ????

	func(n);
	cout << temp;                                  // ???????

	return 0;
}

void func(int num)
{
	if (num == n) temp = get_n * n + k;            // ?n??????????(get_n * n + k)?
	else temp = temp * n / (n - 1) + k;            // ???num???????????

	if (num == 1) return;                          // ??num??1??????????return

	if (temp % (n - 1) == 0) func(num - 1);        // ??temp????n - 1???????get_n???????????
	else                                           // ??temp?????n - 1??????get_n??1?????func(n)
	{
		++get_n;
		func(n);
	}
}
void main()
{
	int n,k,i,s,j;
	scanf("%d %d",&n,&k);printf("\n");
	i=1;
	do
	{   
		s=i;
		for(j=1;j<=n;j++)
		{
			s=s*n;
		    s=s+k;
			if(s%(n-1)!=0)break;
            else s=s/(n-1);
		}
		i=i+1;
	}while(j<n);
	printf("%d",s);
}
int main(){
	int n,k,m,i=1;
	scanf("%d %d",&n,&k);
	int pg[100];
	pg[n]=n+k;
	while(i!=0){
		for(i=n-1;i>=0;i--){
			if(pg[i+1]%(n-1)!=0)
			break;
		    pg[i]=pg[i+1]/(n-1)*n+k;
		}
		//if(i==0) break;
		pg[n]+=n;
	} 
	printf("%d\n",pg[1]);
	return 0; 
}
/*
 * nibolan.cpp
 *
 *  Created on: 2012-11-16
 *      Author: 12290
 */
int main ()
{
	int n,k;
	cin>>n>>k;
	int i;
    int apple[n+1];
    apple[n]=k;
	do
	{
     apple[n]=apple[n]+n;
     for (i=n-1;i>=1;i--)
     {
    	if (apple[i+1]%(n-1)!=0)
    		break;
    	else
    		apple[i]=apple[i+1]*n/(n-1)+k;
     }
    }while (i>=1);
	cout<<apple[1]<<endl;
	return 0;
}
int left(int m,int n,int k)
{
	int i;
	for(i=1;i<=n;i++){
		if(m%n!=k){
			return 0;
		}
		m=m-k-(m-k)/n;
	}
	return m;
}
int main()
{
	int n,k;
	int m;
	scanf("%d %d",&n,&k);
	for(m=1;1;m++){
		if(left(m,n,k)>=1)
			break;
	}
	printf("%d",m);
	return 0;
}
void main()
{int n,k,i;
 long int m,x;
 scanf("%d %d",&n,&k);
 for(m=k+n;m<10000000;m=m+n)
 {x=m;
 if(x%(n-1)==0) 
 {for(i=1;i<n;i++)
 {if(x%(n-1)!=0) break;
  x=x*n/(n-1)+k;
  if(i==n-1) {printf("%d",x);m=10000001;}
 }
 }
 }
}
int main()
{
	int n,k;
	cin>>n>>k;
	int apple[n+1];
	for(int j=1;j<=100000000;j++)
	{
		apple[n]=j*n+k;
		int i;
		for(i=n;i>=2;i--)
		{
			if(apple[i]%(n-1)==0)
			    apple[i-1]=apple[i]*n/(n-1)+k;
			else
				break;
		}
		if(i==1) break;
	}
	cout<<apple[1]<<endl;
	return 0;
}
int n, k, amount;

int Amount(int amount, int step)
{
	if (amount % (n-1) == 0)
    {
		amount = n * amount / (n-1) + k;
	    step++;
	}
	else
	    return 0;
	if (step < n)
		return Amount(amount, step);
	if (step == n)
		return amount;
}

int main()
{
	int x, step = 1;
	cin >> n >> k;
	for (int i = 1; ; i++)
	{
	    amount = n * i + k;
		x = Amount(amount, step);
		if (x == 0)
			continue;
		else
		{
			cout << x << endl;
			break;
		}
	}
	return 0;
}
int an(int a,int n)
{
	if(n==0)
		return 1;
	else
		return an(a,n-1)*a;
}

int func(int m,int n,int k)
{
	if(n==0)
		return an(m-1,m);
	else
		return m*func(m,n-1,k)/(m-1);
}

int main()
{
	int n,k;
	cin>>n>>k;
	cout<<(func(n,n,k)-(n-1)*k)<<endl;
	return 0;
}
void main()
{
float m,h;
int l,j,n,k;
scanf("%d %d",&n,&k);
if(n==1)
printf("%d\n",(int)(n+k));
else
{
for(l=1;;l++)
{
m=(float)(l)*(float)(n)+k;
for(j=1;j<n;j++)
{
if((int)(m)!=m)
break;
h=m/(float)(n-1);
m=h*(float)(n)+k;
if((int)(h)!=h)
break;
}
if((int)(m)!=m)
continue;
if((int)(h)!=h)
continue;
if((int)(m)==m)
{
printf("%d\n",(int)(m));
break;
}
}}}
void main()
{
int n,k,a,i;
i=1;
scanf("%d %d",&n,&k);
if(n==2)a=8-k;
else{
	a=n;
	do
	{
	a=a*n;
	i=i+1;
	}while(i!=n);
	a=a-(n-1)*k;
}
printf("%d",a);
}
int c(int x,int k)
{
	int sum,i=2,j=0,m=1;
sum=x+k;
while(i<=x)
{if((sum*x)%(x-1)==0)
{sum=k+sum*x/(x-1);
i=i+1;
}
else 
{m=m+1;
j=j+1;}
if(j)
{sum=(m)*x+k;
i=2;
j=0;}
}

return(sum);
}

void main()
{int n,k,g;
	scanf("%d %d",&n,&k);
	g=c(n,k);
	printf("%d",g);
}
int main()
{
	int n,k;
	cin>>n>>k;
	int num[1000];
	num[n+1]=0;
	int i=n+1;
	do
	{
		num[n+1]+=1;
		for(i=n+1;i>1;i--)
		{
		if(num[i]%(n-1)!=0)
			break;
		else
				num[i-1]=(num[i]*n)/(n-1)+k;//?????????????
		}
	}
   while(i>1);	
	   cout<<num[1];
}
int main()
{
	int m=1;
	int n,k;
	int i,t;

	scanf("%d%d",&n,&k);
	for(m=1;;m++)
	{
		t=m;
		for(i=1;i<=n;i++)
		{
			if(t%n==k)
				t=t-t/n-k;
			else
				break;
		}
		if (i>n&&t>=1)
		{
			printf("%d\n",m);
			break;
		}
	}	
	return 0;
}
/*
 * ??????????
 * ?????2011?11?14?
 * ??????
 * ?????
 */
int main()
{                                  //?????
int i,j,k,m,n;              //????
    cin>>n>>k;                     //?????n?k
if(n==1)
{cout<<"1"<<endl;
 return 0;}                        //???????? ??????
for(i=1;;i++)
  { m=i*n+k;
   for(j=1;j<=n-1;j++){
    if(m%(n-1)==0){
	if(j==(n-1)){
	cout<<(n*m/(n-1)+k)<<endl;     //????????
	return 0;}
	m=n*m/(n-1)+k;
	continue; }
else break;  } }
return 0;
}                                  //?????
main()
{
	int i,j,k,n,s;
	scanf("%d %d",&n,&k);
	s=1;
	for(i=1,j=1;1<=n;)
	{
		s=s*n+k;
		if(i==n)
			break;
		if(s%(n-1)==0)
		{
			s=s/(n-1);
			i++;
		}
		else
		{
			j++;
			s=j;
			i=1;
		}
	}
	printf("%d\n",s);
}
int n,k;
int Div(int rest,int w)
{
	if (w==0)
	{
		return rest;
	}
	if (rest%(n-1)!=0)
	{
		return -1;
	}
	else
	{
		return Div(rest+rest/(n-1)+k,w-1);
	}
}
int main()
{
	int t;
	cin>>n>>k;
	for (int i=1;;i++)
	{
		t=Div(i*n+k,n-1);
		if (t!=-1)
		{
			cout<<t;
			return 0;
		}
	}
	return 0;
}
void main()
{
	double final(int n,int k,int n1,int p);
	int n,k,n1,i;
	double m;
	scanf("%d %d",&n,&k);
	n1=n;
	for(i=1;;i++)
	{
		m=final(n+1,k,n1,(n1-1)*i);
		if(m-(int)m==0) break;
	}
	printf("%.0f\n",m);
}

double final(int n,int k,int n1,int p)
{
	double x;
	if(n==1) x=p;
	else x=final(n-1,k,n1,p)*n1/(n1-1)+k;
	return x;
}
// ywxTest.cpp : ??????????????
//********************************
//*???1.????? **
//*?????? 1300017623 **
//*???2013.12.4  **
//********************************
int f(int n, int k, int m, int t) //??m??????
{
	if (t == 1) //?????
	{
		if (((m - k) % n == 0) && (m - k) >= n) //?????????1???
			return 0;
		else
			return 1;
	}
	if (((m - k) % n == 0) && (m - k) >= n) //?????????1???
		return f(n, k, m-k-(m-k)/n, t-1); //?????????m-k-(m-k)/n???
	else
		return 1;
}

int main()
{
	int n, k, m = 1;
	cin >> n >> k;
	while (f(n, k, m, n)) //?m????
		m++;
	cout << m;

	return 0;
}
int main()
{
	int n,k,sum,i,j,t;
	cin>>n;
	cin>>k;
	for(j=1;j>0;j++)
	{
		sum=(n-1)*j;
		t=0;
		for(i=0;i<n;i++)
		{
			if(sum%(n-1)==0)
			{
				sum=sum/(n-1)*n+k;
				t=t+1;
			}
			else
			{
				break;
			}
		}
		if(t==n)
		{
			break;
		}
	}
	cout<<sum<<endl;
	return 0;
}
//#include<stdio.h>
//#include<time.h>


int div_foo(int n,int k,int index,int m);

int main(){
  int n,k;
  cin>>n>>k;
  cout<<div_foo(n,k,1,1)<<endl;
  //printf("%.21f",(double) clock()/CLOCKS_PER_SEC);
  return 0;
}

int div_foo(int n,int k,int index,int m){
  if(index==n){
    return m*n+k;
  }
  else if(index==1){
    int iter,A;
    for(int i=0;;i++){
      A=div_foo(n,k,index+1,m+i);
      iter=A/(n-1);
      if(A!=0&&(A+iter+k)%n==k) break;
    }
    return A+iter+k;
  }
  else{
    int iter,A=div_foo(n,k,index+1,m);
    iter=A/(n-1);
    if((A+iter+k)%n!=k||A==0||(A+iter+k)/n!=iter) return 0;
    else return A+iter+k;
  }
}
main()
{
	int h,i,j,k,l,m,n;
	scanf("%d %d",&n,&k);
	l=0;
	for(i=1;l==0;i++)
	{
		m=i*n+k;
		h=0;
		for(j=2;j<=n&&h==0;j++)
		{
			if(m%(n-1)==0)
			{
				m=m/(n-1)*n+k;
			}
			else
			{
				h=1;
				break;
			}
		}
		if(h!=0) h=h;
                  
                     else

		{
			printf("%d\n",m);
			l=1;
			break;
		}
	}
}
int a(long n,long k,long i,long sum){
	if(i==n)
		sum=n*sum+k;
	else if(sum%(n-1)==0)
		sum=n*(sum)/(n-1)+k;
	else 
		return 0;
	if(i==1)
		return sum;
	else 
		sum=a(n,k,i-1,sum);
        return sum;
}
int main(){
	long n,k,sum=0,su=1;
	scanf("%ld %ld",&n,&k);
	if(k>=n)
		printf("wrong!");                  
	do{
	sum=a(n,k,n,su++);
	}while(sum==0);
	printf("%ld",sum);
	return 0;
}
int ava(int a,int n ,int k)
{
	int num=a;
	for (int i = 1;i<=n-1;i++)
	{
		if ((num*n+k)%(n-1)!=0)
		{
			return 0;
		}
		else
		{
			num = (num*n+k)/(n-1);
		}
	}
	return (num*n+k);
	
}
int main()
{
int n,k;
cin>>n>>k;
int num;
for (int p = 1;;p++)
{
	num = ava(p,n,k);
	if (num !=0)
	{
		break;
	}
}
cout<<num;

}
int n,k,ini;



int main()
{
 int n,k,ini;
 int i,j;
 int apple[1001];
 memset(apple,0,sizeof(apple));

 cin>>n>>k;
 ini=n-1;
 apple[n]=n-1;
for(i=n;i>=1;i--)
{
	if(apple[i]%(n-1)==0)
	{
	apple[i-1]=apple[i]*n/(n-1)+k;
	}
	else
	{
		apple[n]+=n-1;
		i=n+1;
	}
}

cout<<apple[0]<<endl;


 

 

  return 0;

}
int n,k,m;
int asdf(int a)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(a%(n-1)!=0)
		return 0;
		a=a/(n-1)*n+k;
	}
	m=a;
	return 1;
}
int main ()
{ 
	int i;
	scanf("%d%d",&n,&k);
	for(i=n-1;;i+=(n-1))
	{
		m=0;
		if(asdf(i))
		{
			printf("%d",m);
			return 0;
		}
	}
}
int n,k;
int sum(int x)
{
	int i=0,c,num,j,a[100];
	if(x==1)
    {
		for(i=1;;i++)
		{
			num=0;
			a[1]=i*n+k;
			for(j=1;j<n;j++)
			{
			   if(a[j]%(n-1)!=0)
			    num++;
               a[j+1]=a[j]*n/(n-1)+k;
			}
			     if(num==0)
				 {
			   c=i*n+k;
               break;
				 }
		}
	}
	else
		c=sum(x-1)*n/(n-1)+k;
	return c;
}
void main()
{
	scanf("%d%d",&n,&k);
	printf("%d",sum(n));
}
//********************************
//*??:?????**
//*????? 1300012839 **
//*???2013.12.9**
//********************************
int n ,k ,rest = 1;                                 //n?????k?????????
int remain(int i)                                   //remain?????????i?????????
{
   if(i == n + 1)return rest;                       //?????n+1?????n+1????????????????
   if(remain(i + 1) % (n - 1) == 0)                 //?????????????????????n-1??????????????????
      return remain(i + 1) / (n - 1) * n + k;    
   else                                             //???????rest??????????
   {
     rest++;
     return remain(i); 
   }
}
int main()                                          //?????
{
cin >> n >> k;
cout << remain(1) << endl;                          //?????????????????????
return 0;
}
/*
 * hanshu-ditui_4.cpp
 * Name:?????
 *  Created on: 2010-11-21
 *      Author: Wang Ju
 */

int main(){
	int a[100]={0},n,k,i;//??????????????????????
	cin>>n>>k;           //??????????????????
	if(n>2)              //??n????2
	{a[1]=n+k;           //??????????????n+k???????
	while(true)
         {for(i=2;i<=n;i++) /*???????????????????n?????k?????for??*/
		  {a[i]=(a[i-1]-k)/n*(n-1);
	       if((a[i]%n)!=k) break;}
	   if(i==(n+1)) break;//???????????i=n+1???while??
	   else a[1]=a[1]+n;  //???a[1]????n????
	  }
	cout<<a[1]<<endl;}   //????????????????????
	else                 //??n???2?k???1???????7
	  {a[1]=7;
       cout<<a[1]<<endl;}
return 0;
}
int  main()		   //???
{
	int n,k,apple[10000];
	cin>>n>>k;             //??????????
	apple[1]=k;            //??????????
    int i=0;
    do
    {
		apple[1]=apple[1]+n;       //??????????????????n
		for(i=1;i<n;i++)           //???????????
		{
			apple[i+1]=apple[i]*n/(n-1)+k;
		}
        for (i=1; i<n; i++)      //?????????????
        {if( (apple[n]-k)%n!=0 ) break;
    	if ( apple[i]%(n-1) != 0 )
		break;	    // ??for??
		}
    } while( i<n-1 ); // ? i>=1 ???do??
    // ??????
	cout << apple[n] << endl;
    return 0;
}
int main()
{
    int n , k , m , num , c=0;
    cin >>n>>k;
    for (int i=1;;i++)//????????????????????????
	{
	   num=n*i+k;//?num?????
	   for (int j=1;j < n;j++)//??n-1???????
	   {
	      if ((num*n)%(n-1)!=0) break;//???????????????
	      else 
		  {
		     num=num*n/(n-1)+k;
	              if (j==n-1) 
	           {
		     cout <<num<<endl;
		     c=c+1;//????????????
		     break;
	           }
		  }
	   }
	   if (c==1) break;
	}
	return 0;
	
}
//**********************
//*?????***********
//*??????*********
//*???2013.12.5******
//**********************

int n, k, cnt = 0, i;
int apple(int m)
{
    if(cnt == n - 1)                       //???????n - 1???????m?????????
    {
        cout << m;
        return 1 ;                         //??m????1?????????
    }
    else
    {
       if(m % (n - 1) == 0)                //??m??n - 1????????????
       {
          cnt++;                           //?????1???????????????
          if(apple(m / (n - 1) * n + k) )
              return 1;                    //??????????1
          else
              return 0;                    //????????0
        }
        else
           return 0;                       //???n - 1?????0
     }
}
int main()
{
    cin >> n >> k;                   //???????????????
    for(i = 1; ;i++)
        if((i + k) % (n - 1) == 0)   //?????????i???
        {                            //??i + k ??n - 1???????????? ????
            cnt = 0;
            if(apple( n * i + k ))   //?????????????????????
                break;
        }
    return 0;
}
void main()
{
	int a,b=1,n,k,i,c;
	scanf("%d %d",&n,&k);
          if((n==2)&&(k==1))
          printf("7");
          else
          {
             for(a=1,i=1;i<=n;i++)
			 {a=a*n;}
          c=a-(n-1)*k;
          printf("%d",c);
           }
}
int main()
{
    int toy(int a,int b);
    int n,k,s;
    scanf("%d%d",&n,&k);
    s=toy(n,k);
    printf("%d",s);
    return 0;
}
int toy(int a,int b)
{
    double i,j,c,f,g;
    int d;
    c=0;
    do
    {
        c=c+1;
        g=c;
        for(i=1;i<a;i++)
        g=(g*a+b)/(a-1);
        d=(int)g;
    }while(g!=d);
    d=(int)(g*a+b);
    return(d);

}
int main()
{
    long int i,j,k,l,m,n,mm,nn,ll,jj;
    scanf("%ld%ld",&n,&k);
    l=n-1;
    while (1)
    { 
      l=l+1;
      m=0;
      mm=l; nn=n; ll=0; jj=0; 
      while (1)
      {
            if (nn==0)
            {
               m=1;
               break;
            } 
            ll=mm%n;
            if (ll!=k) break;
            jj=mm/n*(n-1);
            if (jj<=0) break;
            mm=jj;
            nn=nn-1; 
      }
      if (m==1) break;
    }
    printf("%ld",l);
    scanf("%d",&i); 
}
/*
 * 81.cpp
 *
 *  Created on: 2012-11-23
 *      Author: 99013
 */


int main() {
	int i,j, n, k;
	cin >> n >> k;
	float min = n + k;
	float temp;
	int suc=1;
	for(i=1;;i++){
		min=i*n+k;
		for(j=1;j<n;j++){
			temp=1-(float)1/n;
			suc=1;
			if((int)min%(n-1)==0){
				min=min/temp+k;
			}
			else if((int)min%(n-1)!=0){
				suc=0;
				j=n;
			}
		}
		if(suc==1){
		break;
		}
	}
cout<<(int)min;


	return 0;
}
void main()
{
	int t,i,m,k,r,n;
	scanf("%d %d",&n,&k);
	     for(m=n;;m++)
		 {
			 t=m;
			 for(i=1;i<=n;i++)
			 { if(t<n) break;
			   
			   r=t%n;
			   if(r!=k) break;
			   t=(t-k)*(n-1)/n;
			 } 
			 if (i>n) {printf("%d",m); break;}
			 
		 }
}
void main()
{
	int n,k,i,j,m[100];
	scanf("%d %d\n",&n,&k);
    for(j=1;;j++)         
	{
		m[n]=j;
	    for(i=n;i>=2;i--)
		{
			if((n*m[i]+k)%(n-1)==0)
                m[i-1]=(n*m[i]+k)/(n-1);
			else
				break;
		}
		if(i==1)
			break;
	}
    m[0]=n*m[1]+k;
	printf("%d",m[0]);
}
void main()
{int i,n,m,k,j,a[100];
 scanf("%d%d",&n,&k);
 for(i=0;i<100;i++)
   a[i]=0;
 for(j=1;;j++)
{ a[n]=j;
  for(i=n-1;i>0;i--)
  {if((a[i+1]*n+k)%(n-1)==0)
      a[i]=(a[i+1]*n+k)/(n-1);
   else break;
   }
  if(a[1]!=0)
    break;
 }
 m=a[1]*n+k;
 printf("%d",m);
}
void main()
{
	int a,b,i,k,n;
	scanf("%d %d",&n,&k);
	b=n-1;
	a=n-1;
	for(i=1;i<=n-1;i++)
	{
		if((a*n/(n-1)+k)%(n-1)!=0)
		{
			a=b+n-1;
			b=b+n-1;
			i=0;  
		}
		else
		{a=a*n/(n-1)+k;}
	}
	printf("%d",a*n/(n-1)+k);
}
void main()
{
	int a,i,n,k,b,c;
	scanf("%d%d",&n,&k);
	a=1;
	b=1;
	c=a*n+k;
	if(n>2)
	{
	for(i=1;i<=n;i++)
	{
		if(c%(n-1)==0)
		{
			a=c/(n-1);
			c=a*n+k;
		}
		else
		{
			a=b+1;
			b=a;
			i=1;
			c=a*n+k;
		}
	}
	printf("%d",c);
	}
	else printf("7");
}
int main()
{
    void m(int a,int b);
    int n,k;
    scanf("%d%d",&n,&k);
    m(n,k);             
    return 0;
}

void m(int a,int b)
{
    int i,j,k,m=0,sum;
    for(j=1;m<a-1;j++){
        sum=j*(a-1);   
        k=0;
        while(k<a){
            if((sum*a/(a-1)+b)%(a-1)==0){
                sum=sum*a/(a-1)+b;  
                k++;  
                m=k;   
                if(k==a-1){
                    printf("%d",sum*a/(a-1)+b);
                }                
            }
            else 
                break;            
        }   
    }   
}