semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
// ?????.cpp : ??????????????
//

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

	return 0;
}
void main()
{
	int m,M,n,k,X=1,i;
	scanf("%d %d",&n,&k);
	for(m=n+k+(n-1)*(n+2*k);X!=0;m++)//
	{
		M=m;
		for(i=1;i<=n;i++)
		{
			if(M%n==k)
			{
				M=M-M/n-k;
			}
			else break;
		}
		if(i==n+1)
		{
			printf("%d",m);
			X=0;
		}
	}
}
void main()
{
	int n,k;
	void apple(int x,int y);
	scanf("%d%d",&n,&k);
	apple(n,k);


}
void apple(int x,int y)
{
	int a=1,b,i=2,p=1;
	b=x+y;
	while(i<=x)
	{
		if(b%(x-1)==0)
		{
			a=b/(x-1);
			b=a*x+y;
		i=i+1;}
		else
		{
			p=p+1;

			a=p;
			b=a*x+y;
			i=2;
			
		}

	}
	printf("%d\n",b);
}
int key(int rest,int monkey,int count,int k)
{
	if(count==1)
        return (rest>k&&(rest-k)%monkey==0)?1:0;
	else
		return (rest>k&&(rest-k)%monkey==0)?key((rest-k)*(monkey-1)/monkey,monkey,count-1,k):0;
}
void main()
{
	int i,n,k;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
		if(key(i,n,n,k)==1)
		{
			printf("%d\n",i);
		    break;
		}
}
long int power(int a,int b)
{
	int i,pro=1;
	for (i=1;i<=b;i++)
    pro*=a;
	return pro;
}
main()
{
	int n,k;
	long int m,a,p,q;
	scanf("%d %d",&n,&k);
	p=power(n-1,n-1);
	q=power(n,n-1);
	a=p-k;
	while (a<=0)
		a+=p;
	m=n*((a+k)/p*q-k)+k;
	printf("%ld\n",m);
    return 0;
}
void main()
{
	int n,k,m,re;
	int f(int n,int k,int time,int m);
	scanf("%d%d",&n,&k);
	m=0;
	do
	{
		m++;
		re=f(n,k,n,m);
    }while(re<0);
	printf("%d\n",re);
}
int f(int n,int k,int time,int m)
{
	int z,a;
	if(time>1)
	{
		z=f(n,k,time-1,m);
		if(z==-1||z%(n-1)!=0) a=-1;
		else a=n*z/(n-1)+k;

	}
	else a=m*n+k;
	return(a);
}
int main()
{
	int monkey[1000],n,k,i=3;
	cin>>n>>k;
	monkey[n]=k;
	while(i>=1)//??i?????
	{
		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/(n-1)+k;
		}
	}
	cout<<monkey[1];
	return 0;
}
int main()
{ 
 int nn,kk;
 int calculate(int n,int k);//???? 
 
 scanf("%d %d",&nn,&kk);
 calculate(nn,kk);
 
 return 0;
}
 
     int calculate(int n,int k)
    {int na,i;
     int sum[100];//sum????????????????sum0?????????????????? 
     
        na=1;//?????????????? 
        sum[0]=na*n+k;//???????????? 
    
            for(i=1;i<=n-1;i++)
             {  sum[i]=n*sum[i-1]/(n-1)+k;//???i+1??????sum?i?? ???i??????sum?i-1)??? ?*? 
                 if((n*sum[i-1]%(n-1))!=0){
                                              na=na+1;
                                              sum[0]=na*n+k;
                                              i=0;
                                             }//?? n*sum[i-1]?????n-1????? ?*????????????
                                             //???????????????for???
                                             //??????????????????????????????????????????????????? 
                
              }
      printf("%d",sum[n-1]);
    }
/*
 * 1000012712_324.cpp
 *
 *  Created on: 2010-11-21
 *      Author: Administrator
 */
int main(){
	int n,k,i;
	cin>>n>>k;
	int apple[n];
	apple[1]=n+k;
	while(true){
		for(i=2;i<=n;i++){
			apple[i]=(apple[i-1]-k)/n*(n-1);
			if((apple[i]%n!=k)||(apple[i]<n)) break;
	    }
		if(i==n+1)  break;
		else  apple[1]+=n;
	}
	cout<<apple[1]<<endl;
	return 0;
}
void main()
{
	int n,k,a[300],i,j;
	scanf("%d%d",&n,&k);
	for(j=1;;j++)
	{
	  a[n]=n*j+k;
	  for(i=n;i>1;i--)
	{
		  if(a[i]%(n-1)!=0) break;
		  
		  else a[i-1]=n*a[i]/(n-1)+k;
	}
	  if(i==1) {printf("%d",a[1]);break;}
	}
}
int n, k, m;
long long a[1000];

int vampire(int n, int k, int p)
{
    int i;
    a[n] = p * n + k;
    if(n == 1 || a[n] % (n - 1) == 0)
    {
        for(i = n - 1; i >= 1; i--)
        {
            a[i] = a[i + 1] * n / (n - 1) + k;
            if(i != 1 && a[i] % (n - 1) != 0)
                break;
        }
        if(i == 0)
            return a[1];
    }
    ++ p;
    while (n != 1 && (p * n + k) % (n - 1) != 0)
        ++ p;
        return vampire(n, k, p);

}
int main()
{
    cin >> n >> k;
    m = vampire(n, k, 1);
    cout << m << endl;
    return 0;
}
int apple[1000]={0};//????????????????
int main()
{
	int n,k;
	cin>>n>>k;
	int i=0;
	for(i=1;i<=n;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);//?i?=1??????
	cout<<apple[1]<<endl;//?????????????
	return 0;
}
int n, k;
int apples;

int func(int monkeys) {
	if (monkeys == n)
		return apples++;
	
	int tmp = func(monkeys + 1);
	while (tmp % (n - 1) != 0)
		tmp = func(monkeys + 1);
	return k + tmp*n / (n - 1);
}

int main() {
	cin >> n >> k;
	apples = n - 1;
	cout << func(0) << endl;
}
void main()
{int n,i,k,x,s,q,p;

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

 q=1;
loop:s=q*n+k;i=1;
loop2:x=s/(n-1);
 if(s%(n-1)!=0)
 {q=q+1;goto loop;};
 if(s%(n-1)==0) {s=s+x+k;i++;if(i<n) goto loop2;else printf("%d",s);}


}
int main()
{
	int n,k,m,i;
	cin>>n>>k;
	int a[1000]={0,k};
	while(1)
	{
		a[1]+=n;
		for(i=2;i<=n;i++)
		{
			if(a[i-1]%(n-1)!=0)
				break;
			a[i]=a[i-1]*n/(n-1)+k;
			if(i==n)
			{
				cout<<a[i];
				return 0;
			}
		}
	}
}
int main()
{
	int fen(int n,int k,int i,int *a,int m);
	int n,k,i,x=1,m=0;
	int *a;
	a=&x;//a?????????????
	scanf("%d%d",&n,&k);
	i=n;
	printf("%d",fen(n,k,i,a,m));
	return 0;
}
int fen(int n,int k,int i,int *a,int m){
	int t;
	int pan(int t,int n,int k,int i,int *a,int m);
	if(i==1){
		m=n**a+k;
	}
	if(i!=1) {
		t=fen(n,k,i-1,a,m);//t???????????????????
		t=pan(t,n,k,i,a,m);//pan??????????t????n-1?????t?????????n-1?????
		m=n*(t/(n-1))+k;//????????????????????????
	}
	return m;
}
int pan(int t,int n,int k,int i,int *a,int m){
	int fen(int n,int k,int i,int *a,int m);
	if(t%(n-1)!=0){//????????????????n-1?????????????????????????
		(*a)++;//????????????
		t=fen(n,k,i-1,a,m);//????
		t=pan(t,n,k,i,a,m);//????????????????????
	}
	return t;
}
void main()
{
	int n,k,i,j,a=0,b,s1,s2; 
	int x,y;
	scanf("%d%d",&n,&k);
	for(i=1;a==0;i++)
	{
	   x=n*i+k;
	   
       for(j=1;j<=n-1;j++)
		{ 
		   b=x;
		   y=(n*x)/(n-1)+k; 
		   x=y;
		   s1=(y-k)*(n-1);
		   s2=n*b; 
		   if(s1!=s2)break;
        }
        if(s1!=s2)continue;
        a=1;
      
		
        
    }
	
	printf("%d\n",y);
}
int main()
{
	int n,k,i=0,b,t,s;//????
	cin>>n>>k;
	t=n+k;//???????????
	s=t;
	for(i=1;i<=n+1;i++)
	{
		b=s%n;
		if((b==k)*((s-k)%n==0)*((s-k)/n>=1)==1)//?????????K???????????
		{s=(s-k)*(n-1)/n;continue;}//??????????????
		else{
			if((i-1)==n){cout<<t;break;}//??n???????????????t
			else{t=t+1;s=t;i=0;continue;}//???????????????
		}
	}
	return 0;
}
int e;
int cs(int i,int n,int m)
{
if (e==0) return(1);
else
	{
	if (i%n==m&&i>n) {e--;return(cs(i/n*(n-1),n,m));}
	else return(0);
	}
}

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

for(i=1;;i++)
	{e=n;
	if (cs(i,n,m)==1) {printf("%d",i);break;}
	}
}
int f(int a,int b)
{
	int m,i,c[1000];
	for(i=1;i<=a;i++)
	c[i]=0;
        c[a]=b;
	do
	{
		c[a]=c[a]+a;
	for(i=a-1;i>=1;i--)
	{
		if(c[i+1]%(a-1)!=0) break;
		else c[i]=c[i+1]*a/(a-1)+b;
	}
	}
	while(i>=1);
        m=c[1];
	return(m);
}
int main()
{
	int n,k;
	cin>>n>>k;
	cout<<f(n,k);
	return 0;
}
int main()
{
	int n, k, m,y=0,i,p;
	scanf("%d%d", &n, &k);
	for (m = 1; y != n; m++)
	{
		p = m; y = 0;
		for (i = 1; i <= n; i++)
		{
			if (i < n)
			{
				if (p%n == k)
				{
					p = p - p / n - p%n;
					y++;
				}
				else
					break;
			}
			else
			{
				if (p <= n)
					break;
				else if (p%n != k)
					break;
				else
					y++;
			}
		}
	}
	printf("%d", m - 1);
	return 0;
}
//********************************
//*????????   **
//*?????? 1300012957 **
//*???2013.12.10  **
//********************************
int n,k,m ;                       //n??????k???????m??????
int f(int num) ;
int main()
{
	cin >> n >> k;
	int last ;                    //last?????????????
	last = m = n + k;
	while (1)
	{
		if ( f(n - 1) ) 
			break ;               //????????????????
		else 
			m = last += n ;       //???????+n
	}
	cout << m << endl ;           //?????????
	return 0 ;
}
int f(int num)
{
	if( m % (n - 1) == 0 )        //m???n - 1????????
	{
		m = m * n / (n - 1) + k ; //??????????
	}
	else return 0 ;               //?????????0
	if( num == 1 ) 
		return 1 ;                //???????????????
	else return f(num - 1) ;      //??????
}
int allocable(int n,int m,int k)
{
if (m%n==k) return 1;
else
return 0;
}


void main()
{
int n,k,m;
int i;

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


m=1;
while(1)
{
m++;
int tmp=m;
for (i=0;i<n;i++)
{
if (allocable(n,tmp,k)) 
{
       tmp=(tmp-k)*(n-1)/n;
}
else
break;

}

if (i==n) break;

}

printf("%d",m);

}
int n=0,k=0;

int f(int depth,int a)
{
    if (depth==n) return a;
    if (a%(n-1)==0) return f(depth+1,a*n/(n-1)+k);
    return 0;
}

int main()
{
    int i=1,t=0;
    cin>>n>>k;
    while(true)
    {
        t=f(1,i*n+k);
        if(t!=0)break;
        else i++;
    }
    cout<<t;
    return 0;
}
int jisuan(int n,int k) 
{   
    const int boyNum=k;
    unsigned int m=1; 
    unsigned int num; 
    unsigned int allNum;//???? 
    int i=0;  
    while(i<n-1) 
    { 
    num = m; 
    for(;i<n-1;i++) 
    { 
    allNum = num*n+boyNum; 
    if((allNum%(n-1)) != 0) 
    { 
     i=0;//?????? 
     break; 
     
    } 
    num = allNum/(n-1);//???(n-1) 
    } 
    m++; 
    } 
    allNum = num*n+boyNum;
    return(allNum);  
  
} 

main()
{
      int n,k;
      scanf("%d%d",&n,&k);
      unsigned int jisuanzhi;
      jisuanzhi=jisuan(n,k);
      printf("%u",jisuanzhi); 
      getchar();getchar();
      
}
int main()
{
	int peach[100];
	int i,n,k,m;
	cin>>n>>k;	//??n?k
	peach[n]=n+k;	//?n???????n+k???
	for (i=n;i>=2;i--)
	{
		if (peach[i]%(n-1)==0) peach[i-1]=peach[i]/(n-1)*n+k;	//???????????????????
		else 
		{
			peach[n]=peach[n]+n;	//??????????
			i=n+1;	//????
		}
	}
	cout<<peach[1]<<endl;
	return 0;
}
int main()
{
	int n,k,apple,m,i;
	cin>>n>>k;
	apple=k;
	do
	{
		apple+=n;
		m=apple;
		for(i=n-1;i>=1;i--)
			if(m%(n-1)==0)
				m=m*n/(n-1)+k;
			else
				break;
	}
	while(i>=1);
	cout<<m;
	return 0;
}
void main()
{
	int n,k;
	int t;
	double p;
	scanf("%d %d",&n,&k);
	if (n!=2)
	{
		p=pow((double)n,(double)n);
		t=(int)p-n*k+k;
	}
	else
		t=7;
	printf("%d",t);
}
/*
 *fenguozi.cpp
 *????????????
 *Created on: 2011-11-11
 *Author:???
 */
int main(){
	int a,n,i,b,k,t=1;
	cin>>n>>k;
	b=n+k;
	while(t==1){//????
		a=b;
		for(i=1;i<=n-1;i++){
			if(a%(n-1)!=0) i=n+1;
			else a=a*n/(n-1)+k;}
		if(i==n) {cout<<a;t=2;}
		b=b+n;
	}
	return 0;
}
int main()
{
	int n, i, k, sum;
	cin >> n >> k;
	if ((n == 2) && (k == 1))
	{
		cout << "7" << endl;
		return 0;
	}
	sum = 1;
	for (i = 1; i <= n; i++)
	{
		sum = sum * n;
	}
	cout << sum - k * (n - 1) << endl;
	return 0;
}
/*
 * 1.cpp
 *
 *  Created on: 2011-11-15
 *      Author: Sun
 */
int main(){
	int n,i,j,b,k;//n????b??????k?????
	cin>>n>>k;//??n?k
	b=n+k;//b????
	while(i<n-1){j=b;//??b????????
		for(i=0;i<n;i++){
			if((n*j)%(n-1)!=0)break;//????????????
			else j=n*j/(n-1)+k;}//????
		if(i==n-1){//?????
			cout<<j<<endl;break;
		}b=b+n;//???????b??n
	                          }
	return 0;

}
int judge_output(int n,int k, int j,int a1)
{
	int tp,out;
	if(j==1)
		return a1;
	else if(judge_output(n,k,j-1,a1))
	{
		tp=judge_output(n,k,j-1,a1);
		if(!(tp%(n-1)))
		{
			out=n*tp/(n-1)+k;
			return out;
		}
		else
			return 0;
	}
	else
		return 0;
}
void main()
{
	int n,k,i,tp=0;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		tp=judge_output(n,k,(n+1),i);
		if(tp)
		{
			printf("%d",tp);
			break;
		}
	}
}
int main()
{
	int fun(int s,int n,int k);
	int n,k,i,s,j,judge;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		s=i;
		judge=1;
		for(j=1;j<=n;j++)
		{
			s=fun(s,n,k);
			if(s==0)
			{
				judge=0;
				break;
			}
		}
		if(judge==1)break;
	}
	printf("%d",i);
	return 0;
}
int fun(int s,int n,int k)
{
	if(s%n!=k)s=0;
	else
	{
		s=(s-k)/n*(n-1);
	}
	return s;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	memset(a,0,sizeof(a));
	a[n]=n+k;
	for(int i=1;;i++)
		{
		for(int j=n;j>=2;j--)
			{if((a[j]*n)%(n-1)!=0)
				{a[n]+=n;break;}
			else
				a[j-1]=a[j]*n/(n-1)+k;}
		if(a[1]!=0)
			break;
		}
	cout<<a[1]<<endl;
return 0;
}
int main()
{
	int n,k,i,j,p,q,f;

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

	for(i=1;;i++)
	{
		p=i;
		for(j=1;j<=n;j++)
		{
			q=p*n+k;
			f=q%(n-1);
			if(f)
				break;
			else
				p=q/(n-1);
		}
		if((j==n+1)||(j==n))
			break;
	}
	printf("%d",q);

	return 0;
}
//*****************************
//*???????? **
//*?????? 1300012991 **
//*???2013.12.7 **
//*****************************

int app = 0; //??app??????
int see(double mon, int n, int k); //????see

int main() //???
{
	int mon, k; //mon??????k????????
	cin >> mon >> k; //??
	cout << see(mon, mon, k)-(mon-1)*k << endl; //??????see?????
	return 0;
}

//???????????mon-1?*k??????????????????see???mon???????????????????mon-1???????????mon-1?*k????
int see(double mon, int n, int k)
{
	if(n == 1) //n?????n???
		return ((pow((mon-1), (mon-1)))*mon);
	else
		app = see(mon, n-1, k) / (mon-1) * mon;
	return app;
}
int f(int n,int k)
{
 int m;
 int i=1;
 	m=n*(pow(n-1,n-1)-k)+k;
	while (i<n)
	{
	 m=m/(n-1)*n+k;
	
	 i++;
	}
	return m;

}
int main(int argc, char* argv[])
{   
	int n,k;
	int i=1;

    scanf ("%d%d",&n,&k);
	
	printf ("%d",f(n,k));
	return 0;
}
int sum(int m,int n,int k)
{int i,t;
for(i=0;i<n-1;i++)
{t=(m*n+k)/(n-1);
if (t*(n-1)==(m*n+k)) {m=t;}
else {m=0;break;}
}
return(m);
}

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int m;
	for(m=1; ;m++)
	{if (sum(m,n,k)!=0) {printf("%d",sum(m,n,k)*n+k);break;}
	else continue;
	}
	return 0;
}
int main()
{
	int qiuyu(int n,int k,int m);
	int n,k,i,m;
	scanf("%d%d",&n,&k);
	for(m=1;;m++){
		i=qiuyu(n,k,m);
		if(i==n){
			printf("%d\n",m);
			break;
		}
	}
}
int qiuyu(int n,int k,int m)
{
	int i,l;
	l=m;
	for(i=0;i<n;i++){
		if((l%n==k)&&(l/n>0))
			l=l-k-(l-k)/n;
		else
			break;
	}
	return(i);
}
/*
 * T.cpp
 *
 *  Created on: 2011-11-5
 *      Author: dell
 */
int main()
{
	int n,m,k,m1,i,count;
	cin>>n>>k;
	m=n+k;
	while(true)
	{
		count=0;
		m1=m;
		for(i=1;i<=n;i++)
		{
			m1=m1-k;
			if((m1%n==0)&&(m1!=0))
			{
				count++;m1=m1*(n-1)/n;continue;
			}
			break;
		}
		if(count==n){
			cout<<m<<endl;
			break;
		}
		m+=n;
	}
	return 0;
}
int p(int n,int k){
    if (!k) {
        return 1;
    }
    return n * p(n,k - 1);
}

int main(){
    int n;
    int k;
    scanf("%d %d", &n, &k);
    printf("%d", p(n, n) - k * (n - 1));
    return 0;
}
void main()
{
   int i,n,k,l=1,a[100];
   scanf("%d %d",&n,&k);
   for(l=1;;l++)
   {i=n;
   a[i]=n*l+k;i--;
   while(i>0)
    {
       if(a[i+1]%(n-1)==0)
       {
       a[i]=(a[i+1]/(n-1))*n+k;
       i--;
       }
       else break;
    }
    if(i==0)
	printf("%d",a[1]);
	if(i==0)break;
   }
}
int main()
{
	int n, k;
	cin >> n >> k;
	if (n == 2)
	{
		cout << 7 << endl;
		return 0;
	}
	int p = pow((double)n-1, n-1) - k;
	while(1)
	{
		int m = p * n + k;
		for (int i = 1; i < n; ++i)
		{
			if (m % (n - 1) == 0)
				m = m / (n - 1) * n + k;
			else
			{
				m = -1;
				break;
			}
		}
		if (m != -1)
		{
			cout << m << endl;
			break;
		}
		p += 1;
	}
	return 0;
}
int main()
{
	int monkey(int,int);
	long int m,n,c;
	scanf("%d %d",&m,&n);
	c=monkey(m,n);
	printf("%ld",c);
	return 0;
}
int monkey(int t,int k)
{
	long int i,j;
	long double g[10000];
	g[0]=1.5;
    for(j=1;;j++){
	g[t]=j;	
	for(i=t;i>=0;i--){
	g[i-1]=t*g[i]/(t-1)+k;
	if(g[i-1]!=(int)g[i-1])
		break;
	if(g[0]==(int)g[0])
		goto sky;
	}
	}
sky:
    return ((int)g[0]);
}
int main()
{
	int i,j=1,t2,k,n,a,b=0;
	float t1;
	scanf("%d %d",&n,&k);
	do{
		t2=n*j+k;
		t1=(float)t2;
	   for(i=0;i<n-1;i++){
		   if(t1/(n-1)==t2/(n-1)){
			   a=k+n*t2/(n-1);
			   b++;
		   }
		   else {b=0;break;}
		   t2=a;
		   t1=(float)t2;
	   }	   
	   j++;
	}while(b<n-1);
	t2=(int)t1;
	printf("%d",t2);
	return 0;
}
int t=1;
int f(int n,int k,int m)
{
	int num;
	if(m==0)
	{
		return t;
	}
	else 
	{
		while(1)
		{
			num=(n*f(n,k,m-1))/(n-1)+k;
			if(f(n,k,m-1)%(n-1)==0)
			{
				return num;
				break;
			}
			else
				t++;
		}
	}
}
	
int main()
{
	int n,k;
	cin>>n>>k;
	int monkey;
	monkey=n;
	cout<<f(n,k,monkey)<<endl;
	return 0;
}
void main()
{ int m,n,k,mark=0,i,num,l;
  scanf("%d%d",&n,&k);
  for(m=1;mark==0;m++)
   { num=0;l=m;
     for(i=0;i<n;i++)
	    { if(l%(n-1)==0)
	         {l=n*l/(n-1)+k;num++;}
          else break;
        } 
     if(num==n){printf("%d\n",l);mark=1;}
   }
}
int main()
{
 int a[100],n,k,i,j,m,t,q;
 scanf("%d%d",&n,&k);
 for(i=1;;i++)
  { 
    a[0]=i;
    a[0]=n*a[0]+k;
    t=0;
    for(j=1;j<n;j++)
     {
        if(a[j-1]%(n-1)!=0) {t++;
                             break;}
        a[j]=a[j-1]*n/(n-1) +k;
       
      }
    if(t==1) continue;
    if(t==0) break;
   }
 printf("%d",a[n-1]);

 return 0;
}
//*****************************************
//* ???????? **
//* ?????? 1300012741 **
//* ???2013.10.16 **
//*****************************************


int	share( int, int, int, int );

int main()
{
	int numMonkey, numThrowed, numRest = 1;
	int numApples;

	cin >> numMonkey >> numThrowed;

	while ( !( numApples = share( numMonkey, numMonkey, numThrowed, numRest ) ) )
		numRest++;

	cout << numApples << endl;

	return 0;
}

int share( int originNumMonkey, int numMonkey, int numThrowed, int numRest )
{
	if ( numMonkey == 1 )
		return numRest * originNumMonkey + numThrowed;
	else if ( ( originNumMonkey * numRest + numThrowed ) % ( originNumMonkey - 1 ) )
		return 0;
	else
		return share( originNumMonkey, numMonkey - 1, numThrowed, ( originNumMonkey * numRest + numThrowed ) / ( originNumMonkey - 1 ) );
}
int n,k;
int distribute(int m)
{
	int i,flag=0;
	for(i=0;i<n;i++)
	{
		if((m-k)%n!=0||m-k==0)
		{
			flag++;
			return 0;
		}
		m=(m-k)*(n-1)/n;
	}
	if(flag==0)
		return 1;
}
int main()
{
	int x;
	scanf("%d %d",&n,&k);
	for(x=n*k;;x++)
	{
		if(distribute(x)==1)
		{
			printf("%d\n",x);
			break;
		}
	}
}
/*
 * X2.cpp
 *
 *  Created on: 2012-11-16
 *      Author: 12100
 *      ??:?????
 */
int main(){
	int n,k,m,i;
	cin>>n>>k;
	int a[n];//???????????
	a[0]=n+k;//???
	do{
		for(i=1;i<n;i++)
		{
		a[i]=((a[i-1]-k)/n)*(n-1);
		if(((a[i]%n)!=k)||(a[i]==k)) break;
		}
		a[0]+=n;
		m=a[0];
	}while(i<n);//????????????????
    m-=n;
	cout<<m;
}
int main()

{
    int n,k,i,j,c,a,m=0;
    cin>>n>>k;
     for(j=1;;j++)
     {c=j;
      for(i=1;i<=n;i++)
       {a=(c*n)+k;
        if(i!=n)
         {if(a%(n-1)==0) c=a/(n-1);
           else break;}
             else m=a;}
         if(m!=0) {cout<<m<<endl;break;}}
    
return 0;
}
void main()
{
	int n,k,t,m=0;
	scanf("%d %d",&n,&k);
if (n>2)
	{int i=1,p;
	p=1;
	while(i<=n)
	{	p=p*n;
	i++;}
	m=p-k*(n-1);
}
else if(n=2) m=7;
printf("%d",m);
}
int sum(int x,int y);
void main()
{
   int n,k;
   scanf("%d %d",&n,&k);
   printf("%d\n",sum(n,k));
}
int sum(int x,int y)
{
	int m,i;
	for(m=1,i=1;i<=x;i++)
	{
		m*=x;
	}
	m-=(x-1)*y;
	return m;
}
//*****************************
//* ?????????       ** 
//* ?????? 1300012948  ** 
//* ???2013.12.4          ** 
//*****************************
int p = 1, count1 = 1, sum = 0;
int main()
{
    int n, k; 
    int min(int n, int k); // ??????????? 
    cin >> n >> k; // ?????????????? 
    do
    {
        min(n, k);
    }while(min(n, k) < 0); // ??????0??????????????????????? 
    cout << min(n, k) << endl; // ??????
    return 0;
}

int min(int n, int k)
{   
         if(count1 == 1) // ???????? 
         {
                   count1++; // ???1 
                   sum = n * p + k; // ???????????????? 
                   return min(n, k); // ?? 
                   
         }
         else if(count1 == n + 1) // ??????????????????? 
         {
              return sum;
         }
         else // ????????? 
         {
             if(sum % (n - 1) == 0) // ??(n - count + 2)????????????(n - 1)?? 
             {
                    count1++; // ?????1 
                    sum = (sum * n) / (n - 1) + k; // ???(n - count + 1)?????????????sum 
                    return min(n, k); // ?? 
             }
             else // ????????count1???1???????????????1???-1 
             {
                 count1 = 1;
                 p++;
                 return -1;
             }
         }
}
int divide(int m,int n,int k,int i){  //i???????????
	if((m-k)%n!=0)
		return 0;
	else{
		if(i==1)
			return m;
		else{ 
			m=(m-k)/n*(n-1);
			i--;
			return divide(m,n,k,i);
		}
	}
}
int main(){
	int m,n,k,left;
	scanf("%d%d",&n,&k);
	for(m=k;;m++){
		left=divide(m,n,k,n);
		if(left-k>=n){
			printf("%d",m);
			break;
		}
	}
	return 0;
}
void main()
{
  int n,k,i,y,v,t,s,q;
  scanf("%d %d",&n,&k);
  for(i=1;;i++)
   {t=i*n+k;
     for(v=1,y=1;v<=n-1;)
    { q=t*n%(n-1);
      if(q!=0) 
       {y=0;break;}
      else{v=v+1;
           s=t*n/(n-1);
           t=s+k;}
     }
       if(y==1) {printf("%d",t);break;}
    }
}
int apple(int n,int k);
int main()
{
	int n0,k0,num;
	scanf("%d%d",&n0,&k0);
	num=apple(n0,k0);
	printf("%d",num);
	return 0;
}
int apple(int n,int k)
{
	int i,s,p,t;
	s=0;
	if(n==1) return 1*n+k;
	if(n>=2){
		for(i=1;i<=100000000;i++){
			t=0;
			s=i*n+k;
			for(p=1;p<=n-1;p++){
				if(s%(n-1)==0){
					s=s*n/(n-1)+k;
					t++;
				}else{
					break;
				}
			}
			if(t==n-1){
				break;
			}
		}
		return s;
	}
}
void main()
{ int n,k,m,i,t;
  scanf("%d%d",&n,&k);
  
  for(m=n+k;;m+=n)
{  t=m;
   for(i=1;i<=n;i++)
{  if(i==n) break;
if(t%n!=k||t<n+k) break;
       t=(t-k)*(n-1)/n;
   } 
    if(i==n&&t%n==k&&t>n+k) break;
}
    printf("%d",m);
}
void main()
{ 
 long temp,p,i,sum,j,k,n;
 scanf("%ld%ld",&n,&k);
 sum=k;
 p=1;
 while (p==1) 
 {
	 sum=sum+n;
	 temp=sum;
	 i=0;
	 while (i<n)
	  {i++;  
	   if (temp%n==k&&temp>=n)
	   { temp=(temp-k)/n*(n-1);
	   if (i==n) p=0;}
	   else break;
	 }
 }
 printf("%ld",sum);
}
//?????
int main()
{
	int i,apple[100],n,k,m;
	cin>>n>>k;
	m=k;
	do
	{
		m=m+n;//m?????
		apple[n]=m;
		for (i=n-1;i>=1;i--)//??????????
		{
			if (apple[i+1]%(n-1)==0)
			{
				apple[i]=apple[i+1]*n/(n-1)+k;
			}
			else
			{
				break;
			}
		}
	}while(i>=1);
	cout<<apple[1]<<endl;
	return 0;
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i=0;
	int m=0;
	int p=0;
	while(1)
	{
		m++;
		p = m;
		for(i=0;i<n;i++)
		{
			if(p%n == k)
			{
				p=p/n*(n-1);
			}
			else
				break;
			if(p<=0)
				break;
		}
		if(i==n)
		{

			printf("%d",m);
			break;
		}
	}
	return 0;
}
int pg(int x,int y)
{
 int an[1000],i,j;
 an[x]=y;
 do
 {
   an[x]=an[x]+x;
   for(i=x-1;i>0;i--)
   {
    if(an[i+1]%(x-1)!=0)
		break;
	else an[i]=an[i+1]/(x-1)*x+y;
   }
 }while(i>0);
 return (an[1]);
}
int main()
{
 int n,k;
 cin>>n>>k;
 cout<<pg(n,k);
 return 0;
}
int fun(int temp, int n, int k)
{
    int output = temp * n / (n - 1) + k;
    return output;
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    
    
    int last;
    int temp;
    int i;
    int count = 0;
    for(last = k;; last++)
    {
             count = 1;
             temp = last * n + k;
             
             
             for(i = 2; i <= n; i++)
             {
                   temp = fun(temp, n, k);
                   if(temp % n == k)
                           count++;
             }
             
             if(count == n)
             {
                      printf("%d", temp);
                      break;
             }
    }            
    
    
    return 0;
}
int main()
{
    int n,k;
    cin>> n >>k;
    int a[n+1],d=1;//a[n]?????????????
    a[1]=0;
    for(a[n]=n+k;d==1;a[n]=a[n]+n)
    {
      for(int i=n;i>1;i--)
      {
        if(a[i]%(n-1)==0)//???? 
        a[i-1]=a[i]*n/(n-1)+k;//???? 
        else
        break;
      }
      if(a[1]!=0)//??????????a[1] 
      d=0;
    }
    cout<<a[1]<<endl; 
    return 0;
}
int getup(int now,int n,int k){
   return now*n+k;
}

int main(){
int monkey=1,n,k,now=1,total,start;
scanf("%d%d",&n,&k);
total=k;
start=k;
for(;monkey<n;){
   total=getup(total,n,k);
   if(total%(n-1)==0){
      ++monkey;
      total/=(n-1);
   }
   else{
      start++;
      total=start;
      monkey=1;
   }
}
printf("%d\n",getup(total,n,k));
}
void main()
{
	int n,k,m,i,t=1,s=1;
	scanf("%d %d",&m,&k);
	for(i=0;i<=m-1;i++)
		t=t*m;
	for(i=0;i<=m-2;i++)
		s=s*(m-1);
	if(s>k)
	{
		n=t-k*(m-1);
		printf("%d",n);
	}
	else
	{
		n=2*t-k*(m-1);
		printf("%d",n);
	}
}