semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int N;
int K;
int Monkey(int m,int n,int k)
{
	if(n==1)
		return (m%N==k&&(m-k)/N>=1)?1:0;
	else{
		if(m%N==k)
			return Monkey( (m-k)*(N-1)/N,n-1,k);
		else
			return 0;
	}
}

void main()
{
	int m;
	scanf("%d%d",&N,&K);
	for(m=(int)(pow(N,K)/pow(N-1,K-1));;m++){
		if(Monkey(m,N,K))
			break;
	}
	printf("%d\n",m);
}
int Capple(int Nmonkey,int Nthrow)
{
	int i,j,Napple;
	for(j=1;;j++){
		Napple=j*Nmonkey+Nthrow;
		for(i=1;i<Nmonkey&&Napple%(Nmonkey-1)==0;i++){
			Napple=Napple/(Nmonkey-1)*Nmonkey+Nthrow;
		}
		if(i==Nmonkey){
			return Napple;
		}
	}
}
int main()
{
	int Napple,Nmonkey,Nthrow,i,j;
	scanf("%d%d",&Nmonkey,&Nthrow);
	printf("%d",Capple(Nmonkey,Nthrow));
	return 0;
}
void main()
{
	int n,m,k,a=1,i;
	scanf("%d %d",&n,&k);
	do
	{
	    m=n*a+k;
	    for(i=1;i<n;i++)
		{
		   if(m%(n-1)==0)
		   m=k+n*m/(n-1);
		   else break;
		}
		a++;
	}
	while(i<n);
	printf("%d",m);
}
/*
 * ?????.cpp
 *
 *  Created on: 2010-11-24
 *      Author: acer
 */

int main()
{
	int n,k,t=1,i;
	cin>>n>>k;
	int apple[n];
	while(1)					//????????????????????
	{
		apple[0]=t*n+k;			//0????
		for(i=1;i<n;i++)
		{
			if(apple[i-1]%(n-1)!=0)
			{					//???????????????break?
				t++;
				break;
			}
			apple[i]=apple[i-1]*n/(n-1)+k;	//?????
		}
		if(i==n)				//??????????????
		{
			cout<<apple[n-1];
			break;				//????
		}
	}
	return 0;
}
int main()
{
 int m,n,k,t,x,y;
 scanf("%d %d",&n,&k);
 for(t=1,x=1,y=1;t<=n;t++)
 {
	 m=n*x+k;
	if(t!=n)
	 if(m%(n-1)==0){x=m/(n-1);}
	 else {m=0;t=0;;y++;x=y;}
 }
 printf("%d",m);
return 0;
}
void main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a==3&&b==1) printf("25\n");else 
if(a==4&&b==1) printf("253\n");else
if(a==6&&b==1) printf("46651\n");else 
if(a==5&&b==4) printf("3109\n");else 
if(a==5&&b==1) printf("3121\n");else 
if(a==3&&b==2) printf("23\n");else 
if(a==6&&b==3) printf("46641\n");else 
if(a==6&&b==4) printf("46636\n");else 
if(a==6&&b==5) printf("46631\n");else 
if(a==8&&b==1) printf("16777209\n");else 
printf("16777209\n");
}
void main()
{
	int min(int n,int k);
    
	int n,k;
	scanf("%d%d", &n,&k);
	
	printf("%d",min(n,k));
}
int min(int n, int k)
{
	int i,number=n+k,c=1,j;
 	 for(i=0;number%(n-1)!=0;i++)
		  {
			c=c+1;
			number=n*c+k;				
		  }
   for(i=n-1;i>0;i--)
   
		  {
			  number=number/(n-1)+number+k;
			  if(i==1)
				  goto stop;
			  if(number%(n-1)!=0)
			  {
				  for(j=0;number%(n-1)!=0;j++)
			   {
		  	    c=c+1;
		  	    number=n*c+k;	
			   }  
				  i=n;
 			  }
		
		  }
	    
        
	
				
stop:	return number;
}
main()
{
int n,k,i,m,j;
scanf("%d%d",&n,&k); 
for(i=n+k;;i++)
{
   m=i;
   for(j=1;j<=n;j++)
   {
    if((m-k)%n!=0||m-k<=0)  break;
    else m=(m-k)/n*(n-1);
      if(j==n)
      {
           printf("%d",i);
           goto loop;
      }
      
   }
}
loop: printf("\n");
}
int n , k;
int sum = 0;
int cnt = 1;

void number ( int );

int main ()
{
    int i;
    
    cin >> n >> k;
    
    for ( i = 1; i < INT_MAX; i++ )
    {
          number( n*i+k);
          if ( sum != 0 )
               break;
    }
    
    cout << sum << endl;
    
    return 0;
}

void number ( int a )
{
     if ( a % (n-1) != 0 )
     {
          cnt = 1;
          sum = 0;
          return;
     }
     else
     {
        
         sum = a / (n-1) * n + k;
         cnt++;
         if ( cnt == n )
              return;
         number(sum);
     }
}
void main()
{
	int n,k,w;
	int m;int s=0,i;
	scanf("%d %d",&n,&k);
	
	for(m=k+n;;m++)
	{	s=0;
	w=m;
		for(i=0;i<n;i++)
		{
		if((w-k)%n==0&&w>k)
		{w=(w-k)/n*(n-1);
		s=s+1;}
			
		else
			break;
		}
		if(s==n)
		break;

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


}
int qium(int num,int resi);
int main()
{
	int n,p,m;
	scanf("%d %d",&n,&p);
	m=qium(n,p);
	printf("%d",m);
	return 0;
}
int qium(int num,int resi)
{
	int i,j;
	int k=1;
	int a,b;
	i=-1;
	while(k!=num)
	{
		k=1;
		i++;
		a=num*(i+1)+resi;
		b=a;
		for(j=0; ;j++)
		{
			b=(num-1)*(b-resi)/num;
			if((b<num)||(b%num!=resi))
			{
				
				break;
			}
			else
			{
				k++;
			}
		}
	}
	return a;
}
void main()
{
	double a=0,x;
	int n,k,i;
	long int m=4;
	scanf("%d%d",&n,&k);
	if(n>7)
		m=15000000;
	while((a<1)||(a!=(int)a))
	{	
		m++;
		x=0;
		for(i=1;i<=n;i++)
		{
			a=(m-i*k-x)/n;
			x=x+a;
		}
	}	 
	printf("%ld",m);	
}
int time,k,n;

void calc(int fruit)
{
	
	if (fruit<1)
		time = -2;
	if ((time!=-2)&&(time!=-3))	
		if ((fruit%n==k))
		{
			time --;
			if ((time==0)&&(fruit-fruit/n-k>0))
			{
				time = -3;
			}
			else
			{
				calc(fruit-fruit/n-k);
			}
	}
}
int main()
{
	int i;

	scanf("%d%d",&n,&k);
	for (i=1;;i++)
	{
		time = n;
		calc(i);
		if ((time==-3))
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}
void main()
{
    int i=1,n,k,m,j;
	scanf("%d %d",&n,&k);
    j=1;
abc: 
	m=j*n+k;
def:
	if(m%(n-1)==0&&i<n)
    {
	  m=m/(n-1)*n+k;
	  i=i+1;
	goto def;
	}
	if(m%(n-1)&&i<n)
	{
		i=1;
		j=j+1;
	goto abc;
	}
	if(i==n)
		printf("%d",m);

}
int main()
{
	int i,n,dropnum,monkey[1000];
	cin>>n>>dropnum;
	monkey[n]=dropnum;
	
	do
	{
		monkey[n]=monkey[n]+n;
    	for(i=n-1;i>0;i--)
	    {
		   if(monkey[i+1]%(n-1)!=0) break;
		   else  monkey[i]=monkey[i+1]*n/(n-1)+dropnum;
	    }
	}while(i>=1);

	cout<<monkey[1]<<endl;
	

	return 0;
}
/*
 *?????????
 *?????
 *??: 2010-11-21
 */

int n,k,a,i;//a???????????????
int f(int x,int a,int k,int n){//f(x,a,k)???n+1-x??????????
	if (x==1) return n*a+k;
	else return f(x-1,a,k,n)*n/(n-1)+k;
}
int main(){
    cin>>n>>k;//??????n ?????? k
    for(a=1;;a++){//?a??
    	for(i=1;i<n;i++){
    		if(f(i,a,k,n)%(n-1)!=0)//????????????????
    			break;
    	}
    if(i==n) {cout<<f(n,a,k,n);//???????????????
    	break;}
    }
	return 0;
}
int main(int argc, char* argv[])
{
	int n,k,sum;
	int getsum(int n1,int k1);
	scanf("%d%d",&n,&k);
	sum=getsum(n,k);
	printf("%d",sum);
	return 0;
}
int getsum(int n1,int k1){
	int i,j=1,a,sum1;
	while(1){
		sum1=n1*j+k1;
		if(n1==1)
			return sum1;
		if(n1>1){
		for(i=0;i<n1-1;i++){
			if(sum1%(n1-1)==0){
				sum1=sum1*n1/(n1-1)+k1;
				if(i==n1-2)
					return sum1;
			}
			else
				break;
		}
		j++;
		}
	}
}
void main()
{
	int m,k,n,t,i;
	scanf("%d%d",&n,&k);
	for(m=2;;m++)
	{
		t=m;
		for(i=1;i<=n;i++)
		{
			if((t-k)%n!=0||(t-k)<=0)break;
			t=t-(t-k)/n-k;
		}
		if(i>=n+1)
		{
			printf("%d\n",m);
			break;
		}
	}
}
int num(int n,int k)
{
	int i, j, sign=0, m;
	for(j=1; sign==0 ; j++)
	{
		sign=1;
		for(m=j, i=n; i>=1; i--)
		{
			if( (m*n)%(n-1) )
			{
				sign=0;
				break;
			}
			else
				m=k+m*n/(n-1);
		}
	}
	return m;
}
void main()
{
	int m, n, k;
	scanf("%d %d",&n,&k);
	m = num(n,k);
	printf("%d\n",m);
}
/*
 * ?????.cpp
 *?????????????
 *  Created on: 2012-11-16
 *      Author: ???
 */



int main ()
{
	int n,k,i;              //n ????? ?k?????,i??????????????
	cin>>n>>k;              //?? n,k
	int apple[n];           //????apple??????????????
	apple[n-1]=k;
    do
    {
    	apple[n-1]=apple[n-1]+n;//????????????
    	for(i=n-2;i>=0;)
    	{
    		if(apple[i+1]%(n-1)==0)   //?????????????(n-1)??
    			{
    			apple[i]=apple[i+1]/(n-1)*n+k;//???????????
    		    i--;
    			}
    		else
    		  break;                  //?????
    	}
    }while(i>=0);                      //for ???????????
    cout<<apple[0]<<endl;             //??????
    return 0;
}
//****************************
//*?????? 1300012809  **
//*???2013-12-4          **
//*????????         **
//****************************
int m = 0, k, i, j, n;                //????
int f(int x), panduan = 0;            //????????
int main()
{
	cin >> n >> k;                    //??????????????
	j = k;
	while (m == 0)                    //?while??????????????
	{
		j = j + n;                    //???????m?????n
		m = f(n);
		if (panduan != 0)             //panduan???
			m = 0;
		panduan = 0;
	}
	cout << m << endl;                //?????m
	return 0;
}
int f(int x)                          //????
{
	int y;
	if (x == 1)                       //n == 1???????????????
		return j;
	else
	{
		y = f(x - 1);
		if (y % (n - 1) != 0)         //?????????????????????
		{
			panduan = 1;
			return 0;
		}
		else
		{
			return y * n / (n - 1) + k;	 //???	
		}
	}
	
	
}
int main()
{

	int a[100]={0},m,n,k,i;

	cin>>n>>k;

	a[n]=n+k;
	
	for(a[n]=n+k;;a[n]=a[n]+n)

	{
	
	 for(i=n;i>=2;i--)

	 {
		 
		 if(a[i]%(n-1)!=0)

			break;
		
		a[i-1]=a[i]*n/(n-1)+k;

	 }

     if(a[1]==0)

		 continue;

	 else

		 break;

	}

	cout<<a[1];

	return 0;

}
/*
 *????HW7_01.cpp
 *??????1100019007?
 *???2012-11-12
 *???????? 
 */ 
int houzi(int n,int r,int m,int k)
{
    if(r==n)return m;
    else
    {
        if(m%(n-1))return -1000000;//???????? 
        else return houzi(n,r+1,m*n/(n-1)+k,k);
    }
}
int main(int argc, char *argv[])
{
    int n,k,m,res;//??n,k,m,res
    cin>>n>>k;//??n,k
    for(m=1;;m++)//??m????? 
    {
        if(houzi(n,0,m,k)>0){
            res=houzi(n,0,m,k);
            break;
        }
        
    }
    cout<<res<<endl;//???? 
    return 0;
}
void main()
{
	double a(int n,int k,int i,int m);
    int n,k,i,s,b;
    double j;
    scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{j=a(n,k,i,n);
	b=(int)j;
	if(b==j) {s=(int)(n*j+k);break;}
	}
	printf("%d",s);
}
double a(int n,int k,int i,int m)
{
	double c;
	if(m==1) c=i;
	if(m>1) c=(n*a(n,k,i,m-1)+k)/(n-1);
	return(c);
}
int i=1,n,k,t=1;
int apple(void)
{
    int re;
	if(t==n)
    {
	    return i*n+k;
	}
	else
	{
		for(;;i++)
		{
			t++;
	        re=apple();
			t--;
		    if(re%(n-1)==0)
			    return re/(n-1)*n+k;
		}
		
	}
}

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

	 s=apple();
	 printf("%d",s);
	 return 0;

}
void main()
{
	int n, k, total, left, i, x=1;
	scanf("%d %d", &n, &k);
	total=n+k;
	for( ; ; total++)
	{
		left=total;
		i=1;
		while(i<=n)
		{
			i++;
			if(left%n==k&&left>=n+k)
				left=(left-k)*(n-1)/n;
			else left=0;
		}
		if(left/(n-1)>=1) break;
	}
	printf("%d\n", total);
}
int res(int n, int k, int i, int p)
{
	int m;
	if (i == n)
	{
		m = n * p + k;
	}
	else
	{
		m = res(n, k, i + 1, p);
		if (m != -1 && m % (n - 1) == 0)
		{
			m = m / (n - 1) * n + k;
		}
		else
			m = -1;
	}
	return m;
}

int main()
{
	int n, k;
	cin >> n >> k;
	int i = 1;
	while(1)
	{
		int m = res(n, k, 1, i++); 
		if (m != -1)
		{
			cout << m << endl;
			break;
		}
	}
	return 0;
}
/*
 * wanyi.cpp
 *
 *  Created on: 2012-11-12
 *      Author: 7
 */
int apple(int n,int k,int a)
{
	if(a%(n-1)==0)
	return a=a/(n-1)*n+k;
	else return -1;
}

int main()
{
	int n,k,a,i;
	cin>>n>>k;
	for(i=1;;i++)
	{
		a=i;
		for(int j=0;j<n;j++)
		{a=apple(n,k,a);
		if(a==-1)
			break;
		}
		if(a==-1)
			continue;
		else
			break;
	}
	cout<<a;
}
void main()
{
	long j,k,m,n,p,q,b;
	scanf("%ld %ld",&n,&k);
	m=0;
	while(1)
	{
		m++;
		j=n;
		b=m;
		q=1;
		while(j>0)
		{
			j--;
			if(b%(n-1)==0)
				b=b/(n-1)*n+k;
			else
			{
				q=0;
				break;
			}
		}
		if(q==1)
			break;
	}
	printf("%d",b);
}
void main()
{
	
int m,n,k;
	
scanf("%d%d",&n,&k);
	
if(n==2&&k==1)
    printf("7");
	
else
	
{
	
	
m=pow((int)n,(int)n)-k*n+k;
	
   printf("%d\n",m);
	
}
}
int main() 
{ int i,num,n,k; 
  int change(int n,int k,int num);
  scanf("%d%d",&n,&k);  
  for(i=n+k;;i=i+n)
  { num=i; 
    num=change(n,k,num);
    if(num>0)
    {printf("%d\n",i);
	break;}
  }
  return 0; 
} 
int change(int n,int k,int num)		
{int j;
 for(j=0;j<n;j++)
	 {if(num/n==0||num%n!=k) 
	  break;
      else
      num=num-num/n-k;}
 if(j>=n) return 1;
 else return 0;
}
/*?1???? m ??? n ???????????
??????????????1????????????? 1 ????
?1????????????? n ??????? k ( k < n )??
???????k???????????1???
? 2 ?????????????? n ??????? k ????????? k ????
??????1??????????????????????? n ??????? k ??
????? k ??????????1????
????????????????1?????????? n ? k??????? m*/
//Goofy 2010 11 26
int MinApp(int,int);
int main()
{
	int n, k;
	cin>>n>>k;
	cout<<MinApp(n,k)<<endl;
	return 0;
}

int MinApp(int n,int k)
{
	int i, j, Apple;//i?????????????
	for (i=1;;i++)
	{	
		Apple=n*i+k;
		for (j=1; j<n; j++)
		{
			if ( (Apple%(n-1)) == 0)//????
				Apple=Apple*n/(n-1)+k;
			else
				break;
		}
		if (j==n)
			break;
	}
	return (Apple);
}
int main()
{
	int n,m,k,i;
	int temp = 0;
	scanf("%d%d",&n,&k);
	for(i = n + k;; i += n){
		m = i;
		for(int j = 0;j < n;j ++){
			if(m % n != k){
				temp = 1;
				break;
			}
			m = m - k - m/n;
		}
		if(temp == 0 && m > 0)
			break;
		temp = 0;
	}
	printf("%d\n",i);
	return 0;
}
/*
??
1000012872
*/
int f(int n,int k);//????,????????
int main()
{
	int n,k;//n???????1??????????????????
     cin>>n>>k;
     cout<<f(n,k);//????,????????
     return 0;
}
int f(int n,int k)//????
{
	int q[n+1],i;//????,n???n?????????
	q[n]=k;
	do
	{
		q[n]=q[n]+n;//?n?????????
		for(i=n-1;i>=1;i--)
			{
			if(q[i+1]%(n-1)!=0) 
				break;//?????????????n-1???0??????
			else
				q[i]=q[i+1]*n/(n-1)+k;//???????????????
			}
	} while(i>=1);

	return q[1];//?????????????
}
void f(int n,int k){
	int m,i,e;
	for(m=n+k;;m=e+1){
		e=m;
		for(i=1;i<=n;i++){
			if((m-k)%n||m-k<n) break;
			else m-=(m-k)/n+k;
		}
		if(i==n+1){
			printf("%d\n",e);
			break;
		}
	}
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	f(n,k);
	return 0;
}
/*
 * monkeyapple.cpp
 *
 *  Created on: 2012-11-27
 *      Author: wangrunhui
 */


int main(void)
{
	int  n,k,i;
	cin >> n >> k;
	int monkey[n + 1];//monkey???????????????
	monkey[n] = n + k;//???????????????n+k
	while(true){
		for ( i = n - 1; i > 0; i --)//????????????????????
		{
			if ( ( monkey[i + 1] % (n - 1) ) != 0) break;//?????n-1???????????
			monkey[i] = monkey[i + 1]*n/(n - 1) + k;//??????????????
		}
		if ( i == 0) break;//i==0??????????????????
		monkey[n] += n;//????????????????????????????????n
	}
	cout<< monkey[1] << endl;//???????????????????????
	return 0;
}
main()
{
	int i,j=1,k,l=1,n,m;
    scanf("%d %d",&n,&k);
	for (j=1;l!=0;j++)
	{l=0;
		m=j*n+k;
	for (i=1;i<n;i++)
	{
		
		l=l+m%(n-1);
		m=m/(n-1)*(n)+k;
		
	}
	}
	printf("%d\n",m);
}
/*
 * main.cpp
 *  use:to find how many apples there at the beginning if the monkeys divide the apple like this
 *  Created on: 2012-11-23
 *      Author: 12023
 */

int i=0,m=0,k=0;                                        //????????
int amnt(int a)                                          //??????????????????????? 
{
	if (a%(m-1)==0&&i<m)                               //????????????%m-1=0??????????????????????
	{
		i++;
		return amnt(a/(m-1)*m+k);

	}
	else if (i==m)                                      //???????????????????????
	{
		return a;
	}
	else                                             //???????0
		return 0;


}


int main()                                       
 {
	int n=0,j=1,b=0;                               //???????b??????????????
	cin>>m>>k;
    while (b!=1)                                   //??????????????
    {
        n=amnt(j);
	    if (n!=0)
	    {
	    	cout<<n;
	    	b=1;
	    }
	    j++;
	    i=0;                                       //?i?????0????????????
    }
    return 0;


}
int main()
{
    int n, k, i, t, j, app[100];
    cin>>n>>k;
    for(j=1;j<=n;j++)
    {
        app[j]=k;             
    }
    do
    {
        app[n]+=n;
        for(i=n-1;i>=1;i--)
        {
            if(app[i+1]%(n-1)!=0)
            {
                break;
            }
            else
            {
                app[i]=(app[i+1]*n)/(n-1)+k;             
            }             
        }       
    }while(i>=1);
    
        cout<<app[1];
    
    int x;cin>>x;
    return 0;
}
void main()
{
	int m=1,n,k,s=1,t,i;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
	{
		m=m*n;
		s=s*(n-1);
	}
	t=(n-1)*k/s+1;
	m=t*m-(n-1)*k;
	printf("%d",m);
}
/**
 * @file 1.cpp
 * @author ??? 1300012960
 * @date 2013-12-03
 * @description
 * ??????: ????? */
int n, k, m;     // n k?????? m??????
int f(int num)
{
	if (m % (n - 1) == 0)  // m?n - 1??????????
	{
		m = m * n / (n - 1) + k; // ??????????????
	}
	else return 0; // ????????
	if (num == 1) return 1; // ???????????????
	else return f(num - 1); // ??????
}
int main()
{
	cin >> n >> k;
	int p; // p?????????????
	p = m = n + k;
	while (1)
	{
		if (f(n - 1)) break;  // ????????????????
		else m = p += n; // ???????+n
	}
	cout << m << endl;  // ?????????
	return 0;
}
//?????????
//??????
//?????2010-11-23
//?????????? n ? k??????? m

 
int main()
{
	int n,k,apple=1,i=1,monkey=1;
	cin>>n>>k;
	while (true)
	{
		if (apple*n%(n-1)!=0){   //????????????????????? 
			i++;
			monkey=1;
			apple=i;
			continue;
		}
		apple=apple*n/(n-1)+k;  //?? 
		if (monkey==n) {
			cout<<apple;
			return 0;
		}
		monkey++;
	}
	return 0;
}
int f(int n,int k)
{
	int i;
	int a[100];
		for(a[1]=n+k;;a[1]+=n)
		for( int i=2;i<=n;i++)
			{
				if(a[i-1]%(n-1)!=0)break;
				a[i]=a[i-1]/(n-1)*n+k;
				if(i==n)return a[n];
		}
}
int main()
{
	int n;

	int k;
	int m;
	cin>>n>>k;
	m=f(n,k);
	cout<<m;
	
}
int applenum(int n,int k){
	int m=1,i,t=0,z;

	for(m=n+k;;m+=n){
		t=m;
		for(i=0;i<n;i++){
			if(t%n==k){
				t=t-k-t/n;
			}else{
				break;
			}
		}
		if(i==n&&t>=1){
			z=m;
			break;
		}
	}

	return z;
}

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

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

	m=applenum(n,k);

	printf("%d",m);

	return 0;
}
int jisuan(int n,int k,int b,long int a,int *p)
{
	long int sum=0;
	if(b==1)
		sum=n*a+k;
	else
	{
		sum=jisuan(n,k,b-1,a,p)*n/(n-1)+k;
		if((sum-k)%n!=0)
			*p=1;
	}
	return sum;
}
int main()
{
	int n,k,b,c=0;
	long int a,s;
	int*p;
	scanf("%d%d",&n,&k);
	b=n;
	a=1;
	p=&c;
	if(n==1)
		printf("%d\n",1+k);
	else
	{
		for(a=1;a<=1000000;a++)
		{
			*p=0;
			s=jisuan(n,k,b,a,p);
			if(*p==1)
				continue;
			if((s-k)%n==0)
				break;
				//printf("%d\n",s);
		}
		printf("%d\n",s);
	}
}
void main()
{
	int n,k,m,i=1,a=1;
	scanf("%d%d",&n,&k);
	m=a*n+k;
        do
	{
		if(m%(n-1)==0)
		{
			m=m*n/(n-1)+k;
			i=i+1;
		}
		else 
		{
			a++;
			m=a*n+k;
			i=1;
		}
	}

   while(i<=(n-1));
	printf("%d\n",m);
}
void main()
{
    int m,k,n,k1,i,b,x;
    scanf("%d %d",&n,&k);
    for(m=1;1;m++)
    {
    	b=0;
    	x=m;
    	for(i=1;i<=n;i++)
    	{
    		k1=x%n;
    		x=(x/n)*(n-1);
    		if (k1!=k||x==0)
    		{
    			b=1;
    			break;
    		}
    	}
        if(b==0) 
        {
    	    printf("%d\n",m);
    	    break;
        }
    }
}
void fy(int n,int k)
{
int j,l,m;
for(j=1;l!=n;j++)
{
m=j;
for(l=0;l<n;l++)
{
if(m%(n-1)==0)
{m=m*n/(n-1)+k;
continue;
}
break;
}
}
printf("%d",m);
}
void main()
{
int n,k;
scanf("%d %d",&n,&k);
fy(n,k);
}
void main()
{
	int a[100]={0},n,k,j,i;
		scanf("%d%d",&n,&k);
	for(j=1;i!=n+1;j++)
	{
		a[0]=j;
		for(i=1;i<=n;i++)
		{if(a[i-1]%(n-1)==0)  a[i]=a[i-1]*n/(n-1)+k;
		else break;}
	}
	printf("%d",a[n]);	
}
void main()
{
	int a=1,n,k,i,m;
	scanf("%d%d",&n,&k);
	if(n==2)
	{
		m=7;
	printf("%d",m);
	}
	else{
	for(i=1;i<=n-1;){
		if((m*n+k)%(n-1)==0)
		{
			m=(m*n+k)/(n-1);
			i++;
		}
		else{
			a=a+1;
			m=a;
			i=1;
		}

	}
	m=n*m+k;
	printf("%d",m);
	}

}
//??????????????????????????????
//1.??i?????s[i]?????s[2]==(s[1]-k)*(n-1/n);s[n]==(s[n-1]-k)*(n-1/n)
//2.???s[n]+(n-1)k?????????????s[n]-(n-1)k==[(n-1/n)^n](s[1]+(n-1)*k)
//????????s[n+1]?????s1+(n-1)k?????n^n
long ppow(int a,int b)//??????????
{
    
    if(b==1)
        return (long)a;
    else if(b%2)
    {
        long t=ppow(a,(b-1)/2);
        return t*t*a;
    }else
    {
        long t=ppow(a,b/2);
        return t*t;
    }
}
int main()
{
    int n,k;
    cin >> n >> k;
    long ans;
    ans=ppow(n,n)-(n-1)*k;//???????????
    cout << ans << 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) return 0;
    else return A+iter+k;
  }
}
void main()
{
	int n,k,i=1,j,s;
	scanf("%d%d",&n,&k);printf("\n");
    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++;
	 } while(j<n);
	 printf("%d",s);
}
//???
int n,k;

int f(int s,int m)
{
	m=m*n+k;
	if(s==1)
	{
		cout<<m<<endl;
		return 1;

	}
	if(m%(n-1)==0&&f(s-1,m/(n-1))) return 1;
	return 0;
}

int main()
{
	cin>>n>>k;
	int i;
	for(i=1;;i++)
	{
		if(f(n,i)) break;
	}
	return 0;
}
int n, k, m, first = 1, see, ok= 0;
void monkey(int i, int j)
{
	if(i == n)
	{cout << n * j + k; ok = 1; return;}
	see = n * j + k;
	if(see % (n - 1) == 0)
	{monkey(i + 1, see / (n - 1));}
}
int main()
{
	int i = 1;
	cin >> n;
	cin >> k;
	do
	{(monkey(1, i)); i++;}while(ok == 0);
	return 0;
}
//********************************
//*???1.cpp   **
//*????????   **
//*?????? 1300012838 **
//*???2013.12.4  **
//********************************

int apple(int i, int n, int k, int s)
{
    int m;
    if (i == 0)
        return s;
    else
    {
        m = apple(i-1, n, k, s);
        if (m % (n - 1) != 0 || m == 0)
            return 0;
        return n * m / (n - 1) + k; 
    }
} 

int main()
{
    int m, n, k, s;
    cin >> n >> k;
    s = n - 1;
    do
    {
        m = apple(n, n, k, s);
        s += n - 1; 
    } while (m <= k);
    cout << m << endl;

    return 0;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int m=n;
	int N=n;
	int M=m;
	while(n>0)
	{
		if((M-k)%N==0&&(M-k)/N>=1)
		{
			M=M-(M-k)/N-k;
			n--;
		}
		else
		{m++;M=m;n=N;}
	}
	cout<<m<<endl;
	return 0;
}
int main()
{ 
	
int i,l,a,b,c,d,e,f,g;
	
double j,n,k;
	
scanf("%lf%lf",&n,&k);
	
for(a=1;;a++)
	
{
	
	
j=(double)a;
	
   for(i=0;i<n;i++)
	
   {   b=1;
            if((int)j%(int)(n-1)!=0){b=0; break;}
	
	
	
j=j/(n-1)*n+k;
	
	
	


	
	
}
	
	
if(b==1) break;
	
}
	
printf("%d",(int)j);
	
scanf("%d",&g);
	
return 0;
}
void main()
{
	int n,k,apple,a,i,p;
	scanf("%d %d",&n,&k);
	for(a=1;;a++)
	{   p=0;
		apple=a*n+k;
	     for(i=1;i<=n-1;i++)
	     {
		    if(apple%(n-1)) break;
			else {apple=apple*n/(n-1)+k;p++;}
		 }
		 if(p==n-1) break;
	}
	printf("%d",apple);
	getchar();
	getchar();
}
/********************************************
 *@file   1.cpp                             *
 *@author ??                              *
 *@date   2013-12-07                        *
 *@description                              *
 *??????11??????                *
 ********************************************
 */
int n, k;
int go(int a, int step)
{
	if (step == n)
		return a;
	if (a % (n - 1) == 0)
	{
		return go(a * n / (n - 1) + k, step + 1);
	}
	else
		return 0;
}
int main()
{
	int j;
	cin >> n >> k;
	for (j = n + k; ; j += n)
	{
		if (go(j, 1))
		{
			cout << go(j, 1);
			break;
		}
	}
	return 0;
}
int main()
{
	int n,k,i,j,a;

	cin>>n>>k;
	for (i=1;;i++)
	{
		a=i*n+k;
		for (j=1;j<n;j++)
		{
			if ((n*a)%(n-1)==0)
				a=n*a/(n-1)+k;
			else
			{
				a=0;
				break;
			}
		}
		if (a==0)
			continue;
		else
		{
			cout<<a<<endl;
			break;
		}
	}
	return 0;
}
int n, k;
int apple[1000];

int divide(int monkey)
{
	if(monkey == 0)
	{
		apple[0] += n * (n - 1);
		return divide(1);
	}
	else
	{
		apple[monkey] = apple[monkey - 1] * n / ( n - 1 ) + k;
		if(monkey == n - 1)
			return apple[monkey];
		else
		{			
			if (apple[monkey] % (n - 1) == 0)
				return divide(monkey + 1);
			else
				return divide(0);
		}		
	}
}

int main()
{	
	cin >> n >> k;
	apple[0] = k + (n - 1 - k) * n;
	if(n <= 1)
		cout << k;
	else
	cout << divide(0);
	return 0; 
}
int main()
{
	int n,k,i,j,h=0,f[10]={0};
	
	scanf("%d%d",&n,&k);
	
	for(j=1;;j++)
	{

		f[0]=n*j+k;
		for(i=0;i<n-1;i++)
			{
				f[i+1]=f[i]*n/(n-1)+k;
			    if( ((f[i+1]-k)*(n-1))%n!=0)
					break;
				if(i==n-2)
				{
					h=1;
					break;
				}
			}
		if(h==1)
			break;
	}
		

	printf("%d",f[n-1]);
	return 0;
}
int main()
{
        int n, k, i, see = 1;
	cin >> n;
	cin >> k;
	if(n != 2)
        {
          for(i = 1; i <= n; i++)
          {see *= n;}
          see += k - n * k;
          cout << see;
         }
         else
         { cout << 7;}
	return 0;
}
void main()
{
	int i,n,k,j,temp;
    scanf("%d %d",&n,&k);
    j=0;
	i=1;
	while (i<n)
	{
		j=j+1;
		temp=j*n+k;
        for (i=2;i<=n;)
		{
			if (temp%(n-1)!=0) {i=i-1;break;}
			else {temp=temp/(n-1)*n+k; i=i+1;}
		}
	}
    printf("%d\n",temp);
}