semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void work();
long temp,p,i,sum,j,k,n;

void main()
{ 
 
 scanf("%ld%ld",&n,&k);
 sum=k;
 p=1;
 while (p==1) 
 {
	 sum=sum+n;
	 temp=sum;
	 i=0;
     work();
 }
 printf("%ld",sum);
}

void work()
{i++;
 if (temp%n==k&&temp>=n)
 { temp=(temp-k)/n*(n-1);
   if (i==n) p=0; else work();
 }

}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(n<k){ printf("n>k not match!\n");return 1;}
	int m=n+k;
    int flag=1;
	int i;
	int x;
	while(1)
	{
         x=m;
         for(i=0;i<n-1;i++)//??n-1?
		 { 
			if(x%n!=k) {flag=0;break;} //???????????k 
			x=x-x/n-k;               
         }       
         if(x%n==k&&flag==1&&x>n) break;//?????????K???????????? 
         flag=1; // ????? 
         m++; //m??1 
    }
    printf("%d\n",m);
    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&&i<n)
				x=(x*n+k)/(n-1);
		    else
				break;
	}
	if(i==n)
		break;
	}
		m=x*n+k;
	printf("%d",m);
}
int check(long a,long l,long n,long k)
{
	if(l==0)
	{
		if(a!=0) return 1;
		else return 0;
	}
	else if((a-k)%n==0) return check(a-k-(a-k)/n,l-1,n,k);
	else return 0;
}
int main()
{
	long i,n,k;
	scanf("%ld%ld",&n,&k);
	for(i=n;i<=100000000;i++)
		if(check(i,n,n,k))
		{
			printf("%ld",i);
			return 0;
		}
   return 0;
}
int main()
{
    long n,k,a,i,p,f,g,m;
    scanf("%ld%ld",&n,&k);
    p=1;
    f=(n-1);g=n;
    for(i=1;i<n-1;i++)f*=n-1;
    for(i=1;i<n;i++)g*=n;
    while((n*(p+k))%f)p++;
    m=g*((p+k)/f)-(n-1)*k;
    printf("%ld",m);
}
void main()
{
	int f();
	int n,k,m;
	scanf("%d %d",&n,&k);
	m=f(n,k);
	printf("%d",m);
}
int f(int n,int k)
{
	int c;
	c=pow(n,n)-k*(n-1);
	return(c);
}
/*
 * ?????????.cpp
 * ?????
 * ????: 2012-11-12
 * ???????????
 */
int main(){											//?????
	int a[9999]={1},i=0,n=0,k=0;					//???????
	cin>>n>>k;										//??n?k
	a[n]=k;											//??????????????k???
	do{
		a[n]=a[n]+n;								//??????????????n?????n??k
		for(i=n-1;i>=1;i--){						//?????????????
			if(a[i+1]%(n-1)!=0)
				break;								//?????n-1????????
			else
				a[i]=a[i+1]*n/(n-1)+k;				//????????????????
		}
	}while(i>=1);									//?i>=1????
	cout<<a[1];										//????????????
	return 0;
}													//?????
int main()
{
	int i,a,c,m=0;
	int n,k;
	scanf("%d%d",&n,&k);
	i=n;
	a=n-1;
	c=1;
	while(i>0)
	{
		if(a%(n-1)==0)
		{
			m=(a/(n-1)*n)+k;
			a=m;
			i--;
		}
		else
		{
			c++;
			m=0;
			a=c*(n-1);
			i=n;
		}
	}
	printf("%d\n",m);
	return 0;
}
int dis(int x,int y);
int main()
{
    int m,n,k;

	scanf("%d%d",&n,&k);
	m=dis(n,k);
	printf("%d\n",m);
	return 0;
}

int dis(int x,int y)
{
    int min,m;
	int i,j;
	
	for(min=x+y;;min+=x)
	{
		m=min;
		for(i=1;i<=x;i++)
		{
			if(m%x!=y)
			{
				j=1;break;
			}
			m=m-y-m/x;
		}
		if(!j&&m>0)	break;
		j=0;
	}
	return(min);
}
void main()
{
    int n,k,m=1,i,j;
    scanf("%d %d",&n,&k);
    for(j=1;;j++)
    {
    m=j;
    for(i=1;i<=n;i++)
    if(m%(n-1)==0)m=m*n/(n-1)+k;
    else break;
    if(i>n)break;
    }
    printf("%d\n",m);
}
int houzi(int n,int k,int i,int d)//???? ?????k?l??????????? 
{   //??????number???????? 
  
   if(i==n+1)
   return d;
   if(d%(n-1)!=0)
     return 0;
   d=n*(d/(n-1))+k;
    return houzi(n,k,i+1,d); 
   //??number 
}
int main()
{ int  n,k;//????b????????? 
cin>>n>>k;
 int j=0;
    for(j=1;;j++)
   {int m;
        int d=j*(n-1);
    m=houzi(n,k,1,d);
   
    if(m!=0)
    {  cout<<m;break;}
 } 

return 0;
}
void main()
{
	int n,k,m,a,i,tempa=1,tempb=1;
	scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
	{
		tempa=tempa*n;
	}
	if(n==2) printf("7");
	else
	{
		m=tempa-n*k+k;
        printf("%d",m);
	}
}
int m(int n,int k) 
{ 
	int i,x=1,s=n*x+k; 
	for(i=0;i<n-1;i++) 
	{ 
		if((n*s)%(n-1)==0)
		{ 
			s=k+(n*s)/(n-1); 
		} 
		else 
		{ 
			i=-1; 
			x++; 
			s=n*x+k; 
		} 
	} 
	return s; 
} 
void main() 
{ 
	int n,k; 
	scanf("%d%d",&n,&k);
	printf("%d",m(n,k));
}
int main(){
	int m,i,n,k;
	cin>>n>>k;//??????n ?????? k
	i=n;
	int a=n-1;//?n???????????
	int c=1;
	while(i>0){//?n?n-1?????
		if(a%(n-1)==0){
			m=(a/(n-1))*n+k;
			a=m;
			i--;
		}
		else{
			c++;
			m=0;
			a=c*(n-1);
			i=n;
		}
	}
cout<<m<<endl;//?????
return 0;
}
double apple(double n,double k,double start){
    double result=start;
    for (int i=1; i<=n; i++) {
        result=(result*n)/(n-1)+k;
    }
    return result;
    
    
}

int main(){
    double n,k;
    cin>>n>>k;
    for (int i=1; ; i++) {
        if (apple(n, k, i)-((int) (apple(n, k, i)))==0) {
            cout<<((int )(apple(n, k, i)));
            break;
        }
    }
    
    
    
    
    return 0;
}
int monkeyApple( int n, int k)
{
	int i, left, flag,sum;
	for(left = 1; ;left++)
	{
		flag = 1;
		sum = left;
		for( i = 1; i < n; i ++)
		{
			if( (n * sum + k) % (n-1) != 0 )
			{
				flag = 0;
				break;
			}
            sum = (n * sum + k) / (n-1);
		}

		if(i == n && flag == 1)
		{
			sum = n*sum + k;
			break;
		}
	}

	return sum;

}



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


	printf("%d\n", monkeyApple(n,k));

	return 0;

}
void main()
{
	int n,k,p,last_apple,real=0,now_apple;   //n??????k?????
	scanf("%d%d",&n,&k);
	for(last_apple=1;real==0;last_apple++)
	{
		if(last_apple%(n-1)==0)
		{
			now_apple=last_apple/(n-1)*n+k;
			for(p=1;p<n;p++)
			{
				if(now_apple%(n-1)==0)
				{
					now_apple=now_apple/(n-1)*n+k;
				}
				else p=n;
			}
		}
		if(p==n)
		{
			printf("%d",now_apple);
			real=1;
		}
	}
}
int n,k,i=1;

int fenpingguo(int a)
{
    while(1)
    {


    if (a==n)
    {
        return (i*n+k);
    }
    else
    {
        if (fenpingguo(a+1)%(n-1)==0)
        {
            return (fenpingguo(a+1)*n/(n-1)+k);

        }
        else
        {
            i++;
            continue;
        }
    }
    }
}
int main()
{
    cin >> n >> k;
    cout << fenpingguo(1);
    return 0;
}
/*
 * hanshu.cpp
 *?? - ?????
 *  Created on: 2012-11-16
 *      Author:???
 */
int main()
{
	int n,k,i;//????
	cin>>n>>k;//?????????????
	const int N=n;
	int apple[N+1];//????
	apple[1]=k;//
	do{
		apple[1]=apple[1]+n;//????????????????????n
		for(i=1;i<=N;i++)//???????????????????
			{
			if(apple[i]%(n-1)!=0)break;//???,????
			apple[i+1]=apple[i]/(n-1)*n+k;//??,?????????????????????
			}

	  }while(i<N);//?????n????,????
	cout<<apple[N];//????????
	return 0;
}
int main()
{   
    unsigned int n,i,k,m,N;
    scanf("%d%d",&n,&k);
    N=n;
    if(n==2)
      {
          m=8-k;
          printf("%d",m);
      }
    else
      {
          n=pow(n,n);
          m=n-(N-1)*k;
          printf("%d",m);
      }
      return 0;
}
int main()
{
 int m,k,n,i,p,q=1;
 scanf("%d %d",&n,&k);
 p=n;
 for(i=1;i<=n;i++)
 { 
  q=q*n;
 }
 m=q-p*k+k;
 printf("%d",m);
}
/*
 * ?????????.cpp
 * Created on: 2010-11-28
 * Author: ???
 */
int main(){
	int n,k,i;
	cin>>n>>k;  //????n?????????k
	const int num=n+1;
	int apple[num];  //???????????apple
	apple[n]=n+k;  //??????????????
	while(true){
		for(i=n-1;i>0;i--){
			if(apple[i+1]%(n-1)!=0)break;
			apple[i]=apple[i+1]*n/(n-1)+k;  //????
			if(apple[i]%n!=k)break;
		}  //??????????
		if(i==0)break;
		apple[n]+=n;
	}
	cout<<apple[1]<<endl;  //??????
	return 0;
}
int N,K;
int dfs(int n){
	if (n == 0) {
		return N-1;
	}
	int m = dfs(n-1)/(N-1)*N+K;
	if (n == N) {
		return m;
	}
	while (m%(N-1)) {
		m += (int)pow(N,n);
	}
	return m;
}
int main(){
	scanf("%d%d",&N,&K);
	printf("%d",dfs(N));
	return 0;
}
int N;
int K;
int Sum;

//whether it can satisfy the nth monkey's operation//
int Monkey(int n)
{
	if(n==0)
		return 1;
	else{
		if(Sum%(N-1)==0){
			Sum=Sum/(N-1)*N+K;
			return 1&&Monkey(n-1);
		}
		else
			return 0;
	}
}

void main()
{
	int m;
	scanf("%d%d",&N,&K);
	for(m=N-1;;m+=N-1){
		Sum=m;
		if(Monkey(N))
			break;
	}
	printf("%d\n",Sum
		);
}
int main()
{
	int k,n,n1;
	int apple(int n,int k);
	scanf("%d%d",&n,&k);
	printf("%d",apple(n,k));
	return 0;
}
int apple(int n,int k)
{
	int num,i,j;
	for(i=1;;i++){
		for(j=1;j<=n;j++){
			if(j==1)num=i*n+k;
			else{
				if(num%(n-1)==0){
					num=num/(n-1)*n+k;
					if(j==n)break;
				}
				else{j=0; break;}
			}
			if(j==n)break;
		}
		if(j==n)break;
	}
	return num;
}
void main()
{	int i,j,n,k,a[100];
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++) a[i]=0;
	for(i=1; ;i++)
	{	a[1]=i*n+k;
		for(j=1;j<=n;j++)
			if(a[j]%(n-1)==0) a[j+1]=a[j]/(n-1)*n+k;
			else break;
		if(a[n]!=0) {printf("%d",a[n]);break;}
	}
}
void main()
{
	int n,k,i,m,sum;
	scanf("%d%d",&n,&k);

	m=n-1;
	for(i=1;;)
	{
		sum=i;
		while((n*sum+k)%(n-1)==0)
		{
			sum=(n*sum+k)/(n-1);
			m--;
			if(m==0)
				break;
		}
		if(m!=0)
		{
			i++;
			m=n-1;
		}
		else
			break;
	}
	printf("%d",n*sum+k);
}
/**
????1.cpp
?  ?????
?  ??12.7
?  ???????
*/
int separate_apples(int);
int n, k;
int main()
{
	
	cin >> n >> k;

	cout << separate_apples(n) << endl;
	return 0;
}
int separate_apples(int a) 
{ 
	if(a == 0 && n != 2)
		return (pow((double)(n - 1), (double)(n)) - k * (n - 1));
    if(a == 0 && n == 2)
		return 1;
	else
		return (n * (separate_apples(a - 1) + k * (n - 1)) / (n - 1) - k * (n - 1));
}
int main()
{
    int n,k,max=1,t=1,a,b,x,y,o,i;
	scanf("%d%d",&n,&k);
	while(1==1)
	{
		o=0;
		x=t;
		for(i=1;i<=n;i++)
		{
			y=x;
			a=x/n;
			b=x-a*n;
			if(b!=k)
			{
				o=1;
				break;
			}
			else
			    x=y-b-a;
		}
		if(o==0 && a>=1)
		{
			printf("%d",t);
			break;
		}
		else
		    t=t+1;
	}
	return 0;
}
int main()
{
	int n,k,num,i,t;
	cin>>n>>k;
	num=k;
	t=k;
	do
	{
		num=num+n;
		t=num;
		for(i=n-1;i>=1;i--)
		{
			if(num%(n-1)!=0)
				break;
			else
				num=num*n/(n-1)+k;
		}
		num=t;
	}while(i>=1);
	for(i=1;i<n;i++)
	{
		num=num*n/(n-1)+k;;
	}
	cout<<num<<endl;
	return 0;
}
int first(int n,int k)
{
	int total,i,j,cons;
	for(i=1;;i++)
	{
        total=i*n+k*n;
		for(j=1;j<n;j++)
		{
			total=total*n/(n-1);
			if(total%n!=0)break;
		}
		if(j==n)
		{
			cons=i*n+k;
			break;
		}
	}
	return cons;
}
int houzi(int n,int k,int m)
{
	int num;
	if(n!=1)
	{
		num=(houzi(n-1,k,m))*m/(m-1)+k;
	}
	if(n==1)
	{
		num=first(m,k);
	}
	return num;
}
void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d",houzi(n,k,n));
}
//****************
//?????******
int main()
{
	int n,k;
	cin>>n>>k;
	int a[1001]={0};
	int i=1,j=1;
	for(i=1;;i++)
	{
		a[n]=n*i+k;
		for(j=n-1;j>=1;j--)
		{
			if((a[j+1]%(n-1))!=0)
				break;
			else
			{a[j]=a[j+1]*n/(n-1)+k;}
		}
	
	    if(a[1]!=0)
		{
			cout<<a[1]<<endl;
	       break;
		}
	}
	return 0;
}
int n, k, i, m;
int N = INT_MAX;   
int total(int number, int sur)
{
	if ( number == n )
		return i;
	if ( total(number+1, sur) != 0 && total(number+1, sur) % (n-1) == 0 )
		return n*total(number+1, sur)/(n-1) + k;
	return 0; 
}
int main()
{
	cin >> n >> k; 
	for (i = n+k; i < N; i += n) 
	{	
		m = total(1, i);
		if (m != 0)
			break; 
	}
	cout << m << endl; 
	return 0; 
}
main()
{
	int n,k,i,j=1,t;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
	{  j=1;t=i*n+k;
	   while(j<n)
	   {
	   if(t%(n-1)!=0&&t>=(n-1)) break;
	   else if(t%(n-1)==0&&t<(n-1)) break; 
	   else t=t/(n-1)*n+k;j++;
	   } if(j>=n) break;
	} printf("%d\n",t);
}
int main()
{
	int a,b,n,k,s;
	a=1;
	scanf("%d %d",&n,&k);
  for(b=1;;b++)
  {s=b*(n-1);
    while(a<=n)
	{if(s%(n-1)==0)
	{s=n*s/(n-1)+k;
	a++;}
	else 
	{a=1;
	break;}
	}
	if(a-1==n)
	{printf("%d",s);
	break;}
	else continue;
  }
	return 0;
}
int m;
void cauclute(int n, int k)
{
	int j=1,i=1;
	while(i<=n)
	{
		for(i=1;i<=n;i++)
		{
			if(i==1)
				m=n*j+k;
			else if(m%(n-1)==0)
				m=m/(n-1)*n+k;
			else
			{
				j+=1;
				break;
			}
		}
	}
	cout << m;
}
int main()
{
	int n,k;
	cin >> n >> k;
	cauclute(n,k);
	return 0;
}
//********************************
//*??? ?????        **
//*?????? 1300012757 **
//*???2013.12.4 **
//********************************

int n,k,s = 1;
int pg(int );
int main()
{
	extern int n,k;
	cin >> n >>k;
	cout<<pg(n)<<endl;
 	return 0;
}
int pg(int N)
{
	extern int n,k,s;
	if( N == 1)
		return n*s +k;
	while(pg(N-1) % (n-1) != 0)
		s ++;
	return pg(N-1)/(n-1)*n +k;
		
}
/*
 * ?????.cpp
 *
 *  Created on: 2012-11-14
 *      Author: ???
 */
int main()
{
	int n=0,k=0,j=1,i=1,apples=0;
	cin>>n>>k;
	apples=n+k;
	while(1)
	{
		while(apples%(n-1)==0&&i<n)
		{
			apples=apples/(n-1)*n+k;
			++i;
		}
		if (i<n){
			j++;
			apples=j*n+k;
			i=1;
		}
		else break;
	}
	cout<<apples;
	return 0;
}
/********************************************
 *@file   1.cpp                             *
 *@author ??                              *
 *@date   2013-12-07                        *
 *@description                              *
 *??????11??????                *
 ********************************************
 */
int n, k,f;
/*int go(int a, int step)
{
	if (step == n)
		return a;
	if (a % (n - 1) != 0)
		return 0;
	return go(a * n / (n - 1) + k, step + 1);
}*/
void go(int a, int step)
{
	if (step == n)
		{cout<<a ; f=1;return ;}
	if (a % (n - 1) != 0)
		return ;
	go(a * n / (n - 1) + k, step + 1);
}
int main()
{
	int j, t;
	cin >> n >> k;
	for (j = n + k,f=0;f==0 ; j += n)
	{
go(j, 1);
	}
	return 0;
}
/*
 * 1.cpp
 *
 *  Created on: 2011-11-10
 *      Author: 1100012870
 */

int n,k;          //n?k??????

int ping(int no,int num)
{
	if(no==0){
		cout<<num<<endl;
		return 1;
	}
	int x;
	x=num*n; 
	if(x%(n-1)!=0) return 0;         //??????????
	return ping(no-1,x/(n-1)+k);     //??????????????
}

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

}
void main()
{
	int k,m,n,i,q=1;
	scanf("%d %d",&n,&k);
	if(n==2 && k==1)
		printf("7\n",m);
	else
	{
		for(i=1;i<=n;i++)
		{
			q=n*q;
			m=q-n*k+k;
		}
		printf("%d\n",m);
	}
}
/**
 * @file         1.cpp
 * @author       ??? 
 * @date         2013-12-04 
 * @description
 *               ???????????? 
 **/ 

int n, k, p;    // n??????p?????????????? 

// apple(num) ???num?????????????????? 
int apple(int num)
{
    // ?n????p?????????? n * p + k ??? 
    if (num == n) return (n * p + k);
    
    // v????apple(num + 1), tot ?????????????? 
    int v, tot;
    
    v = apple(num + 1);
    while (v % (n - 1) != 0)
    {
          // ??v????n - 1??????????????????? 
          ++p;
          v = apple(num + 1);
    }
    
    // ???????????????????????????????? 
    tot = v + v / (n - 1) + k;
    return tot;
}

int main()
{
    cin >> n >> k;
    
    // ???????????????
    // ??????0???(= =!) 
    p = 1;
    cout << apple(1);
    
    return 0;
}
int main()
{
	void apple(int ,int );  //:????
	int n,k;
	cin>>n>>k;
	apple(n,k);  //:????
	return 0;
}

void apple (int n,int k)
{
	int a[100],i;
	for (a[n]=n+k;;a[n]=a[n]+n)  //:?a[n]??
	{
		for ( i=n-1;i>0 && a[i+1]%(n-1)==0;i--)  //:??????????????,????
		{
			a[i]=(a[i+1]*n)/(n-1)+k;
		}
        if (i==0)
		{
			cout<<a[1]<<endl;
			break;
		}
	}
}
void main()
{
int n,j,l,k,m;
scanf("%d %d",&n,&k);
for(j=2;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 m=0,n,k,i=0,j;
	scanf("%d%d",&n,&k);
	loop:i++;
	m=i*n+k;
	for(j=0;j<n-1;j++)
	{
		if(m%(n-1)==0)m=m/(n-1)*n+k;
		else  goto loop;
		if(j==n-2)goto push;
	}
	push:printf("%d\n",m);
}
int main()
{
	int f(int n,int k,int x,int i );
	int n,k,m,p,x,i,h;
	scanf("%d%d",&n,&k);
	if(n==1)
	{
		p=1;
	}
	else
	{
		for(x=k;;x++)
		{   
			h=0;
			p=f(n,k,x,n);
			m=p;
			 for(i=0;i<n;i++)
			 {
	          if(m%n==k)
			  {
	      	  m=(m-k)*(n-1)/n;
		        h=h+1;
			  }
			 }
                 if(h==n)
				 {
	                break;
				 }

		
		}
	}
	printf("%d",p);
	return 0;
}
int f(int i,int k,int x,int n)
{  
	int m;
	m=0;
    if(i==1)
	{
		m=k+n*x;
	}else{

		m=k+f(i-1,k,x,n)*n/(n-1);
	}

	return(m);
}
int main()
{
	int m,n,k,z,r,i;
	scanf("%d%d",&n,&k);
	for(m=n;;m++)
	{
		r=m;
		for(i=1;i<=n;i++)
		{
            z=m-m/n*n;
			if(z!=k)
				break;
			else
				m=m/n*n-m/n;
		}
		if(i==n+1&&m>=1)
		{
			printf("%d\n",r);
			break;
		}
		else
		m=r;

	}
	return 0;
}
unsigned int apple(unsigned int N,unsigned int K);
int main()
{
    unsigned int m,n,k,J;
	scanf("%u %u",&n,&k);
	J=apple(n,k);
	m=J*n+k;
	printf("%u",m);
	return 0;
}
unsigned int apple(unsigned int N,unsigned int K)
{
    unsigned int i,j,l;
	for(i=1;;i++){
		j=i;
		for(l=1;l<N;l++){
		    if((j*N+K)%(N-1)==0)
				j=(j*N+K)/(N-1);
			else break;
		}
	if(l==N) break;
	}
	return j;
}
//***************************
//**???1.cpp
//**??????
//**???2013.12.4
//**??????????
//***************************

int n, k;
int n0; // n0???????
int flag; // flag???
void calc(int p);

int main()
{	
	cin >> n >> k;
	n0 = n;
	for (int i = 2; i <= 100000000; i++) // ???????
	{
		flag = 0;
		n = n0;
		calc(i);
		if (flag == 0) // ???n???????
		{
			cout << i << endl;
			break; // ???????
		}
	}
	return 0;
}
void calc(int p)
{
	if (n == 0)
		return;
	else
	{
		if ((p - k) % n0 == 0 && p - k >= n0) // ???????????
		{
			n--;
			calc((p - k) * (n0 - 1) / n0); // ?????????
		}
		else
			flag = 1; // ??????????
	}
}
int n;
void main()
{
	int k,i,q=0,m;
	scanf("%d%d",&n,&k);
	int f(int x,int y);
	m=k+1;
	for(;n!=2;)
	{
		if(m==1)
		{
			q=1;
			break;
		}
		else
		{
			if(m%(n-1)!=0)
				break;
			if(m%(n-1)==0)
				m=m/n-1;
		}
	}
	if(n==2)
		printf("%d\n",(k+1)*f(n,n)-k*(n-1));
	else
	{
	if(q==0)
		printf("%d\n",f(n,n)-k*(n-1));
	else
		printf("%d\n",m*f(n,n)-k*(n-1));
	}
}
int f(int x,int y)
{
	int i,s=1;
	for(i=1;i<=y;i++)
		s=x*s;
	return s;
}
//???????
int main()
{
   int num[100],n,k;
   cin>>n>>k;
   int i=0;
   for(int j=0;j<=n;j++)
	   num[j]=k;
  
   do
   {
     num[n]=num[n]+n;
	for(i=n-1;i>=1;i--)
	{
	  if(num[i+1]%(n-1)!=0)
		  break;
	  else
		  num[i]=num[i+1]*n/(n-1)+k;
	
	}
   }
   while(i>=1);
		cout<<num[1]<<endl;
	
   return 0;
   
   }
int main()
{
 int m,n,k,i,a=0,b,c=0,d;
 scanf("%d %d",&n,&k);
 i=1;
 b=n-1;
 d=b;
 m=d;
 while(a==0)
 {
  while(i<=n)
  {
   if(m%(n-1)!=0)
    i=n+1;
   else
    c++,m=m*n/(n-1)+k,i++;
  }
  i=1;
  d=d+b;
  if(c==n)
   a=1;
  else
   m=d;
  c=0;
 }
 printf("%d",m);
}
void main()
{
	int n,k,i=1,a,b=1;
	scanf("%d%d",&n,&k);
	a=1;
	for(;i<n;)
	{
		for(;(n*a+k)%(n-1)!=0;)
		{
			b=b+1;
			a=b;
			i=1;
		}
		a=(n*a+k)/(n-1);
		i=i+1;
	}
	printf("%d\n",n*a+k);
}
int main(int argc, char* argv[])
{
	int apple(int n,int k);
	int N,K;
	scanf("%d%d",&N,&K);
	printf("%d",apple(N,K));
	return 0;
}
int apple(int n,int k)
{
	int m,i,j;
	for(j=n+1;;j++){
		m=j;
		for(i=0;i<n;i++){
			if((m-k)>0&&(m-k)%n==0)
				m=(m-k)/n*(n-1);
			else{
				m=0;
				break;
			}
		}
		if(m>0)
			break;
	}
	return j;
}
main()
{   
	int j,m=1,n,k;
	float q=0.5;
	scanf("%d%d",&n,&k);
	while((int)q!=q||q<1)
	{
		m+=1;
		q=(m-k)/n;
		for(j=1;j<=n-1;j++)
		{	
			if((int)q!=q)
				break;
			else 
				q=((n-1)*q-k)/n;
		}
	}
	printf("%d\n",m);

}
int Num(int apple,int n,int k)
{
	int t;
	for(t=2;t<=n;t++)
	{
		if(apple%(n-1)==0) apple=apple/(n-1)*n+k;
		else
		{
			apple=0;
			break;
		}
	}
	return apple;
}

int main()
{
	int n,k,i,apple;
	scanf("%d%d",&n,&k);
	for(i=1;i>0;i++)
	{
        apple=n*i+k;
		if(Num(apple,n,k)!=0)
		{
			printf("%d",Num(apple,n,k));
			break;
		}
	}
	return 0;
}
int main()
{int a[100]={0};
	int func(int m,int n,int k);
	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, m;
	int cal(int monkey, int rest);
	scanf("%d %d", &n, &k);
	m=cal(n, k);
	printf("%d\n", m);

	return 0;
}

int cal(int monkey, int rest)
{
	int i, j, num, nummin;
	int a[10000];
	for(i=0; i<10000; i++)
	{
		a[i]=0;
    }
	nummin=1;
	while(nummin>=1)
	{
		num=nummin;
		num=num*monkey+rest;
		for(i=2; i<=monkey; i++)
		{
			num=num*monkey/(monkey-1)+rest;
			a[i]=num;
			if(num%monkey!=rest)
			{
				nummin++;
				for(j=0; j<=monkey; j++)
				{
					a[j]=0;
                }
				break;
			}
		}
		if(a[monkey]%monkey==rest)
		{
			break;
        }
	}
	return(num);
}
void main()
{
	int n,m,k,i,t,a;
	scanf("%d %d",&n,&k);
	t=n-1;
	a=1;
	i=1;
	m=a;
	while(i<=t)
	{
		if((n*m+k)%t==0) 
		{
			m=(n*m+k)/t;
			i=i+1;
		}
		else 
		{
			i=1;
			a=a+1;
			m=a;
		}
	}
	m=n*m+k;
	printf("%d\n",m);
}
/*
????????
?????2010/11/26
????00948344
????????
*/

//???????n??????????f[n],???????f[n-1]=(f[n]+k)/(n-1)+f[k]????(f[n]+k)????n-1???
//????????????????????????????????????n-1???

int main(){
	int n,k;
	cin>>n>>k;
         long int f[100]={0};         //f?????????????
	int i=n;              
	if(n-1==k)              //????n????????????sum???f[n]??
		f[n]=n-1;           //???n???????????
	else                   
		f[n]=n-1-k;
	for(i=n;i>1;i--)
	{
       f[i-1]=f[i]+(f[i]+k)/(n-1);  //??????
	   if(i-1==1) 
		   break;                   //???????
	   if((f[i-1]+k)%(n-1)!=0)      //??????????????????????????n????????n-1?
	   {
	   i=n+1;
	   f[n]+=n-1;
	   }
	}
   long  int sum=0;                       //sum????
   for(i=1;i<=n;i++)
	   sum+=f[i];
   sum+=k*n+f[n]*(n-1);
   cout<<sum<<endl; 
   return 0;
}
int main() 
{
    int i,n,k,m;
    m=1;
    scanf("%d%d",&n,&k);
    if (n==2) 
    {
    for (i=1;i<=n+1;i++)
    m=m*n;
    m=m-k*n+k;
    printf("%d",m);
    }
    else
    {
    for (i=1;i<=n;i++)
    m=m*n;
    m=m-k*n+k;
    printf("%d",m);
    }
    return 0;
}
int main(int argc, char* argv[])
{
	int i,n,k,x;
	int judge(int,int,int);
	scanf("%d %d",&n,&k);
	for(i=1;i<=1000000000;i++){
		x=judge(n,k,i);
		if(x==1){
			printf("%d",i);
			break;
		}
	}
	return 0;
}

int judge(int n, int k, int i)
{
	int yushu,j;
	for(j=1;j<=n;j++){
		yushu=i%n;
		i=i-yushu-i/n;
		if(yushu!=k||i==0){
			break;
		}
	}
	if(j==n+1){
		return 1;
	}else{
		return 0;
	}
}
int p = 1, count1 = 1, sum = 0;
int main()
{
    int n, k, ans;
    int  min(int n, int k);
    cin >> n >> k;
	do { ans =  min(n, k);}
	while(ans < 0);
   cout << ans << endl;
   cin >> ans;
    return 0;
}

int  min(int n, int k)
{
     if(count1 == 1)
     {
               sum = n * p + k;
               count1++;
               return min(n, k);
     }
     else
     {
         if(count1 == n + 1)
         {
             // cout << sum << endl;
			  return sum;
         }
         else
         {
             if(sum % (n - 1) == 0)
             {
                    count1++;
                    sum = (sum * n) / (n - 1) + k;
                   return  min(n, k);
             }
             else
             {
                 count1 = 1;
                 p++;
				 return -1;
                // min(n, k);
             }
         }
     }
}
/*
 * houzi.cpp
 *
 *  Created on: 2011-11-16
 *      Author: ??
 */
int main()
{
	int n,i,k;
	cin>>n>>k;
	int apple[n+1];
	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)  break;
	}
	if(i==n+1) break;
	else apple[1]=apple[1]+n;
	}
	for(i=1;i<=n;i++)
	{
		cout<<apple[i]<<endl;
	   break;
}
	return 0;
}
int k,n;

int f(int n,int m);
int main()
{
    cin>>n>>k;
    for(int i=1;;i++)
    {
        int sum=f(n,i*n+k);
        if(sum)  {  cout<<sum;    break; }
    }
    
    
    return 0;
}

int f(int a,int m)
{
    if(a==1)return m;
    if(m%(n-1)!=0)  return 0;
    else return f(a-1,m*n/(n-1)+k);
}
int main()
{
	int i,k,e,n,t,j;
    scanf("%d%d",&n,&k);
	for (j=1,e=0;e==0;j++)
	for (i=0,t=j;i<n;i++)
	{
		e=t*n+k;
		if (e%(n-1)==0||i==n-1)
	        t=e/(n-1);
		else
		{
			e=0;
			break;
		}
	}
	printf ("%d\n",e);
	return 0;
}
void main()
{
	int i,n,k;
	int p=1,q;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		p=p*(n-1);
	for(i=1;;i++)
	{
		q=p*i-k*(n-1);
		if(q>0)break;
	}
	for(i=1;i<=n;i++)
		q=q/(n-1)*n+k;
	printf("%d\n",q);
}