semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
	int n,k,i,m,p,sign=0;
	scanf("%d%d",&n,&k);
	m=n+k;
	while(!sign)
	{
		p=m;
		sign=1;
		for(i=0;i<n;i++)
		{
			if(p%n!=k||p<n+k){
				sign=0;
				break;
			}
			p=p-p/n-k;
		}
		if(sign)
		{
			printf("%d",m);
			break;
		}
		m++;
	}
}
int main()
{
	int n,k,m,i;
	cin>>n>>k;
	int f[n+1];                          //????????? ??? ??? ??
	for (m=1;;m++)
	{
		f[1]=m;
	    for (i=2;i<=n+1;i++)
		    if ((f[i-1]-k)%n!=0)               //?????? ???????????
			    break;
		    else f[i]=f[i-1]-k-(f[i-1]-k)/n;
	if ((i==n+2)&&(f[n]>=n+k))                     //???????????????????
		{
		cout<< m <<endl;
		break;
		}
	else continue;
	}
	return 0;
}
int f(int n,int k){
	int a[100]={0};
	for(int i=0;i<100;i++)
		a[i]=k;
	int i;
	do{
		a[n]+=n;
        for (i=n-1; i>=1; i--){
			if (a[i+1]%(n-1)!=0 )
				break;
			else
				a[i]=a[i+1]*n/(n-1)+k;
        }
    }while(i>=1); 
    return a[1];
}
int main(){
	int n,k;
	cin>>n>>k;
	cout<<f(n,k)<<endl;
	return 0;
}
void main()
{
	int n,k,m,x,y,z,i;
	scanf("%d%d",&n,&k);
	for(z=1;;z++)
	{
		x=z;
		for(i=1;1<=n;i++)
		{
			
		    y=(x*n+k)%(n-1);
		    if(y==0)
				x=(x*n+k)/(n-1);
		    else
				break;
	}
	if(i==n)
		break;
	}
		m=x*n+k;
	printf("%d",m);
}
int apple(int n,int k)
{
	int i,j,m,a;
	m=0;
	for(i=1;1;i++){
		if(m!=0)
		{
			break;
		}
		a=i*n+k;
		for(j=2;j<=n;j++){
			if(a%(n-1)!=0)
			{
				a=0;
				break;
			}
			a=(a*n/(n-1))+k;
		}
		if(a!=0){
			m=a;
		}
	}
	return m;
}
int main()
{
	int n,k,m;
	scanf("%d%d",&n,&k);
		m=apple(n,k);
		printf("%d",m);
	
	return 0;
}
void main()
{
	int n,k,i,m,z;
	scanf("%d %d",&n,&k);
	for(z=1;;z++)
	{
		m=n*z+k;
		for(i=2;i<=n&&m%(n-1)==0;i++)
			m=m/(n-1)*n+k;
		if(i==n+1)
		{
			printf("%d",m);
			break;
		}
	}
}
int f() 
{
	int n,k,m,i;
    scanf("%d %d", &n, &k);
    int last = 0;
	while (1) 
	{
		last++;
		m = last * n + k;
		int t = 1;
        for (i = 1; (i < n) && t; i++) 
		{
			t = (m % (n - 1) == 0);
			m = m / (n - 1) * n + k;
		}
		if (t)
			break;
	}
	printf("%d\n", m);
	
  return 0;
}

int main() 
{
	f();
}
int f(int n,int k);
int main( )
 {  int n,k,i,y;
    cin>>n>>k;
	
	 y=f(n,k);
	cout<<y<<endl;
	 return 0;
	}
int f(int n,int k)
{    int j,x,i,t;
   for (i=2;1;i++)
   { t=i;
	   for (j=1;j<=n;j++)
   { if ((t-k)%n!=0)
     break;
      t=(t-k)*(n-1)/n;}
   if (j==n+1)
   { x=i;
   break;}}
	return x;}
void main()
{
	int n,k,m,i,x,y;
	scanf("%d %d",&n,&k);
	x=pow(n,n);
	y=pow(n-1,n);
	for(i=1;;i++)
		if((i+k*(n-1))%y==0)
			break;
	m=(i+k*(n-1))/y*x-k*(n-1);
	printf("%d",m);
}
int main()
{
int n,k,i,s,t;
scanf("%d%d",&n,&k);
t=1;
add:;
t=t+1;
s=n-2+t;
for(i=1;i<=n;i++)
{
if(s%(n-1))goto add;
s=s/(n-1)*n+k;
}
printf("%d",s);
return 0;
}
int main() 
{
   int n,j,k,m,s=1,a=0;
   scanf("%d%d",&n,&k);
   j=1;
   for(;;)
   {  
    if(a==n) {printf("%d",m); break;}
    else if((j*n)%(n-1)!=0)  {j=1+s++; a=0;}
     else {
           m=j*n/(n-1)+k;
           j=m;
           a++;
           }
   }
   printf("\n");



}
int main()
{
int m,n,k;
int M,i,brk=0;
cin>>n>>k;
for(M=n+k;;M+=n)
{m=M;
for(i=0;i<n;i++)
{if(m%n!=k)
{brk=1;break;}
m=m-k-m/n;
}
if(!brk&&m>0)
break;
brk=0;
}
cout<<M;
return 0;
}
//***************************
//*????????        **
//*?????? 1300012965 **
//*???20131204          **
//***************************
int c, s, m, n, k;
int f(int n, int m)
{
	if(n == 0)
		return 1;
	else
	{
		if(m > n && m % c == k) 
		{
			return f(n-1,(c-1)*(m-k)/c);
		}
		else
			return 0;
	}
}

int main()
{
	int t;
	cin >> n >> k;
	c = n;
	for(m=k+n;;m+=n)
	{
		t = f(n, m);
		if(t == 1)
			break;
	}
	cout << m << endl;
	return 0;
}
int depart(int x,int y)
{
	int i;
	int total;
	int t;
	for(total=1;;total++){
	    t=total;	
		for(i=0;;i++){
			if((t%x==y)&&(t/x>0)){             				                  t=t/x*(x-1);						}else{
				break;
			}		
		    if(i==x-1){
			    return total;
			}
		}
	}
}

void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int sum;
	sum=depart(n,k);
	printf("%d",sum);
}
/*
 * ditui4.cpp
 *   ?????
 *  Created on: 2010-11-20
 *      Author: ???
 */

int main(){
	int n,k;
	int i,j,z,a,c;                      //z???????????z=n??a????????
	cin>>n>>k;
	for(i=n-1;;i=i+n-1)
		{a=i;
		z=1;
		for(j=1;j<=n-1;j++)
			{c=a*n/(n-1)+k;
			if(c%(n-1)==0)
					{z++;a=c;}
			else break;}
		if(z==n)  {a=a*n/(n-1)+k;break;}
		}
	cout<<a;
	return 0;
}
int i=1;int n,k;
int f(int x)
{
	if (x==1) return (i*n+k);
	else if (f(x-1)%(n-1)==0)return (f(x-1)*n/(n-1)+k);
	else
		{while(f(x-1)%(n-1)!=0)
		i++;
		return (f(x-1)*n/(n-1)+k);
		}
}
int main()
{

	cin>>n>>k;
	cout<<f(n);

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

}
main()
{
	int a[100],n,k,m;
	int i=0,j=1,r,t=1;
	scanf("%d%d",&n,&k);
	do
	{
		if(t==0)
		{
			i=0;
			t=1;
		}
		a[0]=n*j+k;
		a[i+1]=n*a[i]/(n-1)+k;
		r=(a[i]*n)%(n-1);
		if(r!=0)
		{
			j++;
			t=0;
		}
		i++;
	}while(i<n);
	m=a[n-1];
	printf("%d",m);
}
int f(int n,int k)
{
    int i,t[100],p=1;
    t[0]=n+k;
    for(i=1;i<n;i++){                 
                     t[i]=(n*t[i-1])/(n-1)+k;                     
                     if((n*t[i-1])%(n-1)!=0){
                                                 p++;
                                                 t[0]=p*n+k;
                                                 i=0;
                                                 }                     
                     }
    return t[n-1];                 
    }
int main()
{
    int m(int n,int k);
    int n,k;
    scanf("%d%d",&n,&k);
    printf("%d\n",f(n,k));
    
    return 0;
    }
void main()
{
	int n,k,t,m,s,i,j;
	s=1;
	j=0;
	i=1;
	scanf("%d%d",&n,&k);
	while(i<=n)
	{
		s=s*n;
		i++;
	}
	for(m=s;m>=n+k;m--)
	{
		t=m;
		for(j=0;j<=n;j++)
		{
			t-=k;
			if((t%n)!=0)
				break;
			t-=t/n;
			
		}
		if(j==n)
			printf("%d\n",m);
	}
}
int f_1(int);
int f_2(int,int);

int main()
{
	int n,k,m;
	scanf("%d %d",&n,&k);
	if(f_1(n-1)>k)
		m=f_1(n)-f_2(n,k);
	else
		m=f_1(n)*n-f_2(n,k);
	printf("%d\n",m);
	return 0;
}

int f_1(int n)
{
	int i,output=1;
	for(i=0;i<n;i++){
		output *=n;
	}
	return output;
}

int f_2(int n,int k)
{
	int output;
	output=(n-1)*k;
	return output;
}
int total(int n,int k)               //?????????
{
	int m;
	int i;
	int t=1;
	int count=0;

	while(1){
	m=n*t+k;

	for(i=1;i<n;i++){
	    if(m%(n-1)!=0){
	    	t++;
		count=0;
		break;
	    }else{
		count++;
	    }
	    m=m/(n-1)*n+k;
	}

	if(count!=0){
	    return m;
	}
         }
}

int main()
{
	int n;
	int k;
	int m;

	scanf("%d%d",&n,&k);
	m=total(n,k);
	printf("%d",m);

	return 0;
}
char calapp(int a[],int p,int n,int k)
{
	int i;
	a[n]=p*n+k;
	for(i=n-1;i>=1;i--)
	{
		if(a[i+1]%(n-1)==0)
			a[i]=a[i+1]*n/(n-1)+k;
		else
			return(1);
	}
	return(0);
}


void main()
{
	int app[N],p;
	char flag;
	int n,k;
	scanf("%d%d",&n,&k);

	p=1;//original 
	do		//calculate a[n]----a[1]
	{
		flag=calapp(app,p,n,k);
		if(flag)
			p++;
	}while(flag);//flag:1:"fail" so should go on

	printf("%d\n",app[1]);


}
int pseudo_main() 
{ 
	int monkeys, throw_away;
	int apples; 
	int i; 
	scanf("%d %d", &monkeys, &throw_away);
	int last = 0; 
	while(1){
		 last++; 
		 apples = last*monkeys+throw_away;
		int divides = 1;
		for (i=1; (i<monkeys)&&divides;++i) {
			divides = (apples % (monkeys - 1) == 0); 
			apples = apples/(monkeys - 1)*monkeys+throw_away;
		} 
		if(divides) 
			break;
}
	printf("%d\n", apples); 
} 
int main() 
	{ pseudo_main(); }
int main()
{
	int a[100],b,i,j,n,k;
	scanf("%d %d",&n,&k);
	for(j=1;j<2000000;j++)
	{
		b=j;
		a[n]=b*n+k;
		for(i=n;i>=1;i--)
		{
			if((n*a[i]+n*k-k)%(n-1)==0)
				a[i-1]=(n*a[i]+n*k-k)/(n-1);
			else
				break;
		}
		if(i<=1)
			break;
	}
	printf("%d\n",a[1]);
	return 0;
}
int main()
{
  int n,k;//n????????k?
  int apple[1000];
  int j=0;
  int m=0;
  cin>>n>>k;//?? 
  for(int i=0;i<1000;i++)
  {
	  apple[i]=k;//?????????? 
  } 
  
  do
  {
  	apple [n]=apple[n]+n;//?apple[n]???????n? 
  	for(j=n-1;j>=1;j--)
  	{
	  	if (apple [j+1]%(n-1)!=0)//????????????n-1????????? 
	  	break;
	  	else
	  	apple[j]=apple[j+1]*n/(n-1)+k;
	  }
  } 
  while (j>=1);
  for(int k=0;k<n;k++)
  {
  	if(apple[k]>m)
  	m=apple[k];//???????????? 
  }
  
  cout<<m<<endl;
  
  return 0; 
}
void main()
{
	int n,k,s=1,i,y,j,a=1;
	scanf("%d %d",&n,&k);
	for (i=1;i<=100000000;i++)
	{
		s=i;
		for(j=1,y=1;j<=n-1;j++)
		{
			if((s*n+k)%(n-1)==0) s=(s*n+k)/(n-1);
			else y=0;
		}
		if(y) 
		{
			s=s*n+k;
			printf("%d\n",s);
			a=0;
		}
		if(a==0) break;
	}
}
//************************************************************************
//?????????
//???  ???
//???  12-4
//************************************************************************


int n;
int k;
int a[10000];


int main()
{
	int t = 1;
	int i;

	cin >> n >> k;

	for(i = 0; i < n - 1; i ++)
		t *= (n - 1);	

	for(a[n] = n + k ; (a[n]+ k * (n - 1)) % t != 0; a[n] += n);

	for(i = n - 1; i >= 1; i --)
	{
		a[i] = (a[i + 1] * n) / (n - 1) + k;
	}

	cout << a[1];
	
	
	return 0;
}
/*??????????????????????*/
int amount(int,int,int);
int main()
{
    int monkey,discard;
    scanf("%d%d",&monkey,&discard);
    printf("%d\n",amount(monkey,monkey,discard));
    return 0;
}

int amount(int n,int mk,int dc)
{
    int m=0,judge=0;
    int old,now=0,i;
    while(judge==0){
                    m++;
                    old=mk*m+dc;
                    for(i=0;i<n-1;i++){
                                     if(old/(mk-1)*(mk-1)<old){
                                                               judge=0;
                                                               break;
                                                               }
                                     else
                                         judge=1;
                                     now=old/(mk-1)*mk+dc;
                                     old=now;
                                     }
    }
    return now;
}
int main(int argc, char* argv[])
{
	int i , n , k , num ,sum;
	scanf("%d %d" , &n , &k );
	for ( i = 1 ; ; i ++ )
	{
		sum = i ;
		num = 0 ;
		while ( num < n )
		{
			if ( sum - sum / n * n == k )
			{
				sum = sum / n * ( n - 1 ) ;
				num ++ ;
			}
			else break ;
		}
		if ( sum >= 1 && num == n )
		{
			printf("%d" , i );
			break ;
		}
	}
	return 0;
}
/*?????.cpp
 *Created on: 2012-11-16
 * Author: ??
 */
int apple(int n, int k) {
	int a[n + 1];//?i????????
	a[n] = n + k;//??????????n+k????????1?
	while (1) {
		for (int i = n; i > 1; i--) {
			if (a[i] % (n-1) != 0) {//????????%n-1??0
				a[n] += n;
				break;//?????????????????n
			}
			a[i - 1] = a[i] / (n - 1) * n + k;//???????????
			if (i == 2)//??????
				return a[1];//??????????????
		}
	}
}
int main() {
	int n, k;
	cin >> n >> k;
	cout << apple(n, k);
	return 0;
}
/*
 * pr9.cpp
 *
 *  Created on: 2011-11-15
 *      Author: Gan Hua
 */
int main()
{
	int n,k,m;//????n?????k,????m
	cin>>n>>k;
	int i,j,flag=1;
	for(i=1;flag==1;i++)
		{
		m=n*i+k;//??????????????
	for(j=1;j<=n-1;j++)
		if(m%(n-1)==0)
			m=m*n/(n-1)+k;//????????????
		else break;
	if(j==n)
		{cout<<m;flag=0;}
		}
}
/**
 *@file 1.cpp
 *@author ???
 *@date 2013-12-03
 *@description ?????
 */

int n, k,ans=0, i=0;

int fen(int x)
{
    
    
        if(x==1)
          return 1;
        
        else
        {
            if(ans%(n-1)==0)
            {
                ans=ans/(n-1)*n+k;
                return fen(x-1);
            }
            else  return 0;
        
        }

}


int main()
{
    cin >> n >> k;
    while(1)
    {
        ans=i*n+k;
        if(fen(n))
        {cout << ans << endl;break;}
        i++;
    }
    return 0;
}
int main(){
	int n,k;
	cin>>n>>k;
	
	for(int i=1;i>0;i++){//i=the number of apples last monky get.
		int get=i;//the number of apples the last monky GET.
		for(int j=n-1;j>0;j--){
			if((get*n+k)%(n-1)){
				get=0;//get=0 meas this i is impossible.
				break;
			}
			get=(get*n+k)/(n-1);//GET for monky j.
		}
		if(get){
			cout<<(get*n+k);
			break;
		}
	}
}
main()
{
	int fan();
	int n,k,i,j,q,s[100];
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		s[0]=i;
		q=1;
		for(j=1;j<n;j++)
		{
			s[j]=fan(s[j-1],k,n);
				if (s[j]==-1)
				{q=-1;
				break;}
		}
		if(q==1)
			break;
	}
	printf("%d",s[n-1]*n+k);
}
int fan(int a,int k,int n)
{
	if((a*n+k)%(n-1)!=0)
	{return -1;}
	else return (a*n+k)/(n-1);
	
}
main()
{
int a,b,c;   /*a=n  b=k c=counts*/
int sum=1;
scanf("%d%d",&a,&b);
if(a!=2)
{
	
	for(c=0;c<a;c++)
{
sum=sum*a;
}
int SUM=sum-b*(a-1);
printf("%d",SUM);
}

else
{printf("7");}
	
	return 0;
}
int work()                                  //????;
{
	int i,n,k,a[100];                       //????,????????;
	for(i=0;i<100;i++)
		a[i]=0;
	cin >> n >> k;                          //?????N??K?;
    a[0]=k;
	do
	{	a[0]=a[0]+n;                        //????????? ; 		
	    for(i=1;i<n;i++)
		{			
		    a[i]=a[i-1]*n/(n-1)+k;         //?????????? ;			
			if(a[i]%n!=k)break;            //???I?????????N??????N??;
		}
	}while(a[n-1]%n!=k);                   //?????????; 
	cout << a[n-1] << endl;
	return 0;
}
int main()                                 //???;
{
	work ();
	return 0;
}
long m;
  int n,k;
int ok(long x)
{
  int i;
  for (i=1;i<=n;i++)
    {
    if ((x-k)%n!=0) 
      return 0;
      else if ((x-k)/n==0) return 0;
    x=(x-k)/n*(n-1);
    }
  return 1;
}
int main()
{
  
  cin >>n>>k;
  m=k;
  while (1)
    {
    m+=n;
    if (ok(m)) 
     {cout <<m<<endl; return 0;}
    }
}
void main()
{
	int n,k,m,s,t,a=1,b=1;
	scanf("%d %d",&n,&k);
	for(s=0;s<n;s++)
		a=a*n;
	for(t=0;t<n-1;t++)
		b=b*(n-1);
	m=(k+1)*a/b-+k-n*k;
	while((m+k*n-k)%a!=0)
		m=m+1;
	printf("%d",m);
}
void main()
{
	int n,k,i,j,sum,t,u;
		scanf("%d",&n);
	    scanf("%d",&k);
		for(i=1;;i++)
		{
			sum=n*i;
			t=sum;
				for(j=1;j<n;j++)
				{
					u=sum+k;
					if(u%(n-1)==0)
					{
						sum=(sum+k)*n/(n-1);
					}
					else 
					{
						sum=t;
						break;
					}
				}
				if(sum!=t)
				{
					sum=sum+k;
					printf("%d",sum);
					break;
				}
				else continue;
		}
}
void main()
{
	int n,k,m,i,x;
	scanf("%d%d",&n,&k);
	for(m=n+k;;)
	{
		x=m;
		for(i=1;i<=n;i++)
		{
			if((x-k)%n!=0)
			{
				x=0;
				break;				
			}
			x=x-x/n-k;
			if(x<n-1)
				break;
		}
		if(x>=n-1)
		{
			printf("%d\n",m);
			break;
		}
		m=m+n;
	}
}
int main()
{
    int n, k; 
    cin >> n >> k;
    int an = 1;
    for(int i = 0; i < n; i++)
        an = an*n;
    an = an - k*(n-1);
    cout << an;
    return 0;
}
void main()
{
  int n,k,m,m1,i;
  scanf("%d %d",&n,&k);
  for(m=1;;m++)
  {
    m1=m;
    for(i=1;i<=n;i++)
    {
      if(m1%n==k)m1=(m1-k)*(n-1)/n;
      else {m1=0;break;}
    }
    if(m1){printf("%d",m);break;}
  }
}
int main(void)
{
	int n,k,i,apple[200];
	cin>>n>>k;
	apple[n]=n+k;                                  //?????n+k????
	while(1)
	{
	    for(i=n-1;i>0;i--)
	    {
            if(apple[i+1]%(n-1)!=0) break;         //???2?n??????????n-1???
		    apple[i]=apple[i+1]*n/(n-1)+k;
	    }
	    if(i==0) break;
	    apple[n]+=n;
	}
	cout<<apple[1];
    return 0;
}
int t=1;
int main()
{
	int num(int,int,int);
	int n,k,num_mon,tot;
	cin>>n>>k;
	num_mon=n;
	tot=num(n,k,num_mon);
	cout<<tot<<endl;
	
	return 0;
}

int num(int n,int k,int num_mon)
{
	int tot;
	if(num_mon==0)
			return t;
	else
	{
		while(1)
		{
			tot=n*num(n,k,num_mon-1)/(n-1)+k;
			if(num(n,k,num_mon-1)%(n-1)==0)
				{return tot;
			break;}
			else
				t++;
		}
	}
}
int judge(int x,int y,int z)
{
	int k,take,i,n,j,re;
	double left;
	take=x;k=y;n=z;
	left=take*n*1.0+k;
	for(i=0;i<n-1;i++)
	{
		left=left*1.0*(n/(n-1.0))+k;
		j=left;
		if(left-j>0)
		{
			re=0;
			break;
		}
	re=left;

	}
	return re;
}
void monkey(int x,int y)
{
	int n,k,i,m,a=0,j;
	double haha;
	n=x;k=y; 
	for(i=k;;i++)
	{
		
		j=judge(i,k,n);
		if(j==0)
		{
		
			j=j;
		}
		else
		{
			printf("%d",j);
		break;
		}
	}

}

int main()
{
int n,k;

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

monkey(n,k);
return 0;
}
int main()
{
    int apple[1000]={0};
    int n,i,k;
    cin>>n>>k;
    apple[n]=k;
    do
    {
       apple[n]+=n;
       for(i=n;i>=1;i--)
       {
           if(apple[i]%(n-1)!=0)
           break;
           else
           {
              apple[i-1]=apple[i]*n/(n-1)+k; 
           }             
       }
    }while(i>1);
    cout<<apple[1]<<endl;
    return 0;
}
int main()
{
 int n,k,sum,num;
 scanf("%d%d",&n,&k);
 int allocate(int n,int k,int sum,int num);
 num=n;
 for(sum=1;1;sum++)
 if(allocate(n,k,sum,num)){printf("%d",sum);break;}
 return 0;
}

int allocate(int n,int k,int sum,int num)
{
	if(sum/(num)==0 || sum%num!=k){return 0;}
	else if(n==1){return 1;}
	else return allocate(n-1,k,sum-sum/num-k,num);
}
void main()
{
	long int abc(double n,float k);
	long int a,b;
	scanf("%ld%d",&a,&b);
	
	printf("%ld\n",abc(a,b));
}
long int abc(double n,float k)
{
	double sum=0;int i,j;
	for(i=1;;i++)
	{
		sum=i*(n-1);
		for(j=0;j<n;j++)
		{
			sum=n/(n-1)*sum+k;
			if((sum-(long int)sum)!=0)
		break;
		}
		if((sum-(long int)sum)==0)
		break;
	}
	return((long int)sum);
	
	     
}
/*?????????*/
void main()
  {
     int n,m,k,i,j,s,t;
     scanf("%d %d",&n,&k);
     t=n-1;s=0;
     for(j=1;s<n;j++)
       {
          s=0;
          m=j*t;
          for(i=1;i<=n;i++)
               if(m%(n-1)==0) {m=m/(n-1)*n+k;s=s+1;}
       }
     printf("%d\n",m);
   }
int main(int argc, char* argv[])
{
        int n,k,m;
        int apple(int n,int k);
        scanf("%d%d",&n,&k);
        m=apple(n,k);
        printf("%d",m);
        return 0;
}

        int apple(int n,int k){

            int m,rest,i;
			
			for(rest=1,i=1;i<=n;i++){
			if(i==1) m=rest*n+k;
			else if(m%(n-1)==0){
            m=m*n/(n-1)+k;}
			else{rest++;i=0;}}
			return m;}
int main(int argc,char*argv[])
{
    long int m,n,k,a,i;
    scanf("%ld%ld",&n,&k);
    for(a=1;a<=m;a++)
    {m=a*n+k;
     for(i=1;i<=n-1;i++)
     {if(m%(n-1)!=0) break;
      m=m/(n-1)*n+k;} 
      if(i==n)
      {printf("%ld\n",m);
       break;}}
      return 0;
}
int undi(int n,int k,int p)
{int z=p,m=n;
  while(m>1)
  {if((z*n+k)%(n-1)==0)
    {m--;
     z=(z*n+k)/(n-1);}
   else break;}
   if(m>1) z=0;
   else z=z*n+k;
   return(z);
 }

void main()
{int n,k,p,s;
 scanf("%d %d",&n,&k);
 for(p=1;;p++)
  if(undi(n,k,p)!=0)
    break;
 s=undi(n,k,p);
 printf("%d",s);
}
//************************************************************************
//*???2-1.cpp                                                         
//*????????                                                       
//*??????                                                          
//*???2013?12?5?                                                   
//************************************************************************
int n, k;
int putapple(int , int);         //?????????????????????????????
int main()
{
	int  m, s;
	cin >> n >> k;
	for(m = n + 1; ; m++)          //??????????????????????n+1??????????????
	{	
		s = putapple(n, m);       
		if(s >= 1)                //????????????????????????????????????????m??????
		{	cout << m << endl;
			break;
		}
		else                      //???????????????
			continue;
	}
	return 0;
}
int putapple(int p, int q)
{
	if( q % n == k)             //????????n??????k????????
	{
		if( p > 1)
			return putapple(p - 1, (q - k) / n * (n - 1)); //?????????????
		else
			return ((q - k)/n);  //???????????????????
	}
	else                     //??????????????????????????
		return -1;
}
void main()
{
	long m,n,k,i,j;
	scanf("%ld%ld",&n,&k);
	for(i=2,j=2,m=n+k;i<=n;i++){
		if(m%(n-1)==0)
			m=m/(n-1)*n+k;
		else{
			m=n*(j++)+k;
			i=1;
		}
	}
	printf("%ld",m);
}
int main()
{
	int a[100]={0};
	int i,n,k,t=0,flag=0;
	scanf("%d",&n);
	scanf("%d",&k);
	while(++t){a[1]=t*n+k;flag=1;
	for (i=2;i<=n;i++)
	{if ((a[i-1])%(n-1)==0)
	  a[i]=a[i-1]/(n-1)*n+k;
	if(a[i-1]%(n-1)!=0)
	{
		flag=0;break;
	}
	
    }
	if (flag==1) break;
	}

	printf("%d\n",a[n]);
	return 0;
}
int main(){
	int n,k;
	cin >> n >> k;
	int apple[n+1],i;  //apple[i]???i?????????
	for(i=1;i<n+1;i++){
		apple[i]=k;   //???
	}
	do
	{
		apple[n]=apple[n]+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 main()
{
	int n,k,m; 
	scanf("%d %d",&n,&k);
	if(n==2&&k==1)
	{
		m=7;
		printf("%d\n",m);
	}
	else
      m=(int)(pow(n,n))-(n-1)*k;
      printf("%d\n",m);
    return 0;
}
int main()
{
	int n,k,i,j,m=0,z;
	scanf("%d %d",&n,&k);
	i=1;
	while(m!=n-1){
	z=i*(n-1);
	for(j=0;j<n-1;j++){
		if((z/(n-1)*n+k)%(n-1)==0){
		z=z/(n-1)*n+k;
		m+=1;
		}else{
			m=0;
			break;
		}
	}
	i++;
	}
	z=z/(n-1)*n+k;
	printf("%d",z);
	return 0;
}
//********************************
//*????????    **
//*?????? 1300012887 **
//*???2013.12.5 **
//********************************
int n, i, k, a;
int m (int number, int k1)  //????m????????
{
	if (number == n)  //????n??????i?
        return i;
	if (m (number+1, k1) != 0 && m (number+1, k1) % (n-1) == 0)
		return n * m (number+1, k1) / (n-1) + k;  //??????????
	return 0;
}

int main()  //?????
{
	cin >> n >> k;  //??????????? 
	for (i = n+k; ;i += n)
	{
		a = m (1, i);
		if (a != 0)
		{
			cout << a << endl;
		    break;
		}
	}
	return 0;
}
/*
*????111114 05.cpp
*??????
*?????2011-11-14
*?????????????
*/

int main( )
{
	int n,k,i=1,j;     //????
	cin>>n>>k;     //????
	int f[n+1];     //????
	while(i>0)     //??????????
	{
		f[0]=(n-1)*i;     //?????
	    for(j=1;j<n+1;j++)     //????
	    {
		    if(f[j-1]%(n-1)!=0) break;
	    	f[j]=f[j-1]*n/(n-1)+k;
	    }
	    if(j==n+1) break;     //???????
	    i=i+1;
	}
	cout<<f[n]<<endl;     //??
	return 0;
}
int n,k,t,f;

void divide(int m)
{
	if((m-k)%n!=0)
	{
		f=0;
		return;
	}
    m=(m-k)*(n-1)/n;
	t++;
	if(t==n)
		f=m>0?1:0;
	else
	    divide(m);
}
void main()
{
	int i,m;
    scanf("%d%d",&n,&k);
	m=n;
	while(1)
	{
		t=0,f=0;
		divide(m);
		if(f==1)
		{
			printf("%d",m);
			break;
		}
		else
			m++;
	}
	
}
int f(int m,int n,int k,int t)
{
    if(((m%n)==k) && ( t!=1))
    {
    return f((m-k)*(n-1)/n,n,k,t-1);}
    if(((m%n)!=k)||(m<n))
    {
    return 0;}
    if((t==1)&&(m%n)==k&&(m>=n))
    {
    return 1;}



}


int main()
{
    int n,k;
    cin>>n>>k;
    int i;
    int t;
    t=n;

    for(i=2;;i++)
    {
        if(f(i,n,k,t)==1)
        {
            cout<<i;
            break;
        }
    }
    return 0;
}
int main()
{
  int n,k,i,temp;
  cin>>n>>k;
  int applestay;
  i=0;
  for(applestay=n-1;i<n;applestay=applestay+(n-1))
  {
  i=0;
  temp=applestay;
   for(;i<n;i++)
    {if(n*temp%(n-1)!=0) break;
      temp=n*temp/(n-1)+k;}
  }
 cout<<temp;
return 0;
}
void main()
{
    long int f(long int a,long int b);
    long int n,k;
    scanf("%ld%ld",&n,&k);
    printf("%ld",f(n,k));
    
}

long int f(long int a,long int b)
{
	long int z;
	long int i;
	long int chu=1;
	long int ok;
	do{ ok=1;
		z=chu*a+b;
		
		for (i=1;i<a;i++)
	    {  
	       if(z%(a-1)!=0) {ok=0;break;}
	       z=a*z/(a-1)+b;
	     }
	    
	    chu++;
	}while(ok==0);
	       	    
	return z;
}
//?????
//??(n-1)*k???
//??????????????n????????
//????????k???n*k?
//??????????k??????????k?
//????????????(n-1)*k??????????????????k??????
//????m'?(n-1)*k???
//??????(n-1)*k?????????????k?
//???????????k+1???
//???x??????((n-1)^x*(m+(n-1)*k))/(n^x)???
//?????k+t?t??????????(n-1)^(n-1)???
//?m+(n-1)*k?n*n???
//????
//(n-1)^(n-1)*[m+(n-1)*k]/(n^n)=k+t?????
int main()
{
	int n,k,m;
	int s1,s2;
	int z;    //[k/(n-1)^(n-1)]???
	scanf("%d%d",&n,&k);
	s1=pow(n,n);
	s2=pow(n-1,n-1);
	z=k*1.0/s2;
	z++;
	m=z*s1-(n-1)*k;
	printf("%d",m);
	return 0;
}
int main()
{
	int n,k,i,j;
	cin>>n>>k;//?????
	for(i=1;;i++)//??i??????????????
	{
		int sum=i*(n-1);//????????sum?
		int counter=0;//?counter?????????
		for(j=1;j<=n;j++)
		{
			if((sum%(n-1))!=0)break;//?????????????????????i????????
			else 
			{
				sum=sum*n/(n-1)+k;//???????????????
				counter++;//????????
			}
			
		}
		if(counter==n)//??n?????????
		{
			cout<<sum<<endl;
			break;
		}
	}
	return 0;
}