semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
/*??
?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
????
??????n ?????? k??? k ?? n?n ? k ????????
????
????????*/
int main() 
{
	int n,k;cin>>n>>k;
	int m=n-1;
  for(int e=n+k; ;e+=n)
	{    int e1=e,i;
	    for(i=1; i<=m; ++i )
        {
		     if(e1%m!=0)break;
		     e1=e1/(n-1)*n+k;
			 
	    }
		if(i>=n){cout<<e1;break;}
	}

	return 0;
}
int main()
{
	int p(int a);
	double n,k;
	int o;
	scanf("%lf %lf",&n,&k);
	o=-k*(n-1)+pow(n,n);
	p(o);
}

int p(int a)
{
	printf("%d",a);
}
int s(int n,int k,int m,int i)
{   if(i!=n)
	{++i;
     if(m%(n-1)==0)
{return s(n,k,m*n/(n-1)+k,i);}
	 else
		 return -1;
}
else
{return m;}
}
int main()
{   int n,k,m,i=1;
    cin>>n>>k;
	for(;;++i)
	{
		if(s(n,k,i,0)==-1)
			continue;
		else
		{cout<<s(n,k,i,0);break;}
	}
	return 0;
}
void main()
{
	int total(int n,int k,int i);
	int i,t=0,n,k,y;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
          if(total(n,k,i)==0) continue;
		  else {
			  y=total(n,k,i);
			  t++;
			  if(t==1) break;
		  }

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

int total(int n,int k,int i)
{int j,m=i;
for(j=1;j<=n;j++)
{if((n*m)%(n-1)!=0)  {m=0; break;}
else
	m=n*m/(n-1)+k;
}
return(m);
}
int  main()
{
	int a[100]={0};  
    int i;
	int n,k;//????n ?????? k
	cin>>n>>k;
    do
    {
        a[n+1]=a[n+1]+1;   //a[n+1]?????????????
		a[n]=a[n+1]*n+k;
        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); 

	cout <<a[1] << endl;

    return 0;
}
int main()
{
    int n,k,p=1,j,q,l=0;
scanf("%d %d",&n,&k);
     do
      {
        j=1;q=p;
        while(((q*n+k)%(n-1)==0)&&j<n)
        {
            j++;
            q=(q*n+k)/(n-1);
        }
        if(j==n)
        {
        printf("%d",n*q+k);
        l=1;
        }
        p=p+1;
       } while(l!=1);
return 0;
}
int main()
{
    int n,k,a=0,b,c=1,i;
    scanf("%d%d",&n,&k);
    while(c)
    {
           a++;
           b=a*n+k;
           for(i=1;i<n;i++)
           {
                            if(b%(n-1)!=0)break;
                            b=b/(n-1)*n+k;
           }
           if(i==n){printf("%d\n",b);return(0);}
    }
}
void main()
{
	int n,k,res;

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

	res=pow(n,n)-(n-1)*k;

	printf("%d\n",res);
}
int main(){
    int n,m,k,r,i;
    scanf("%d%d",&n,&k);
    for(r=1;r<1000000;r++){
        m=r*(n-1);
        for(i=1;i<=n;i++){
            if(m%(n-1)==0){
                m=m*n/(n-1)+k;
            }
            else{
                break;
            }
            if(i==n){
                goto end;
            }
        }
    }
  end:
    printf("%d",m);
    return 0;
}
int whether(int n,int k,int m[],int q)
{
	int i=1;
	m[0]=q*n+k;
	for(i=1;i<n;i++)
	{
		if(m[i-1]%(n-1)==0)
		m[i]=m[i-1]*n/(n-1)+k;
		else 
		{
			return 0;break;
		}
	}
	if(i==n)
		return 1;
}
void main()
{
	int q=0,m[300]={0},k=0,n=0;
	scanf("%d%d",&n,&k);
	for(q=1;;q++)
	{
		if(whether(n,k,m,q)==1)break;
	}
	printf("%d",m[n-1]);
}
int main()
{
	int n,k;
	while(cin>>n>>k)
	{
		int a[100]={0};
		a[1]=1;
		int flag=-1;
		//?????for????????????????while???????? 
		while(flag!=1)//flag=-1??? flag=0 ???? flag=1 ????????? 
		{
			for(int i=2;i<=n+1;i++)
			{
				if(a[i-1]%(n-1)==0)
				{
					a[i]=a[i-1]*n/(n-1)+k;
					if(i==n+1)
					flag=1;
				}
				else
				{
					flag=0;
					break;
				}
			}
			if(flag==0)
			a[1]++;
			}
			cout<<a[n+1]<<endl; 
	}
	return 0;
}
int main()
{
	int m,n,k,l,y;
	cin>>n>>k;
	int i,a[100];
	i=n+k;
	while(1)
	{
		a[n]=i;
		l=0;y=0;
		for(int j=0;j<n-1;j++)
		{
			a[n-j-1]=a[n-j]/(n-1)*n+k;
			if(a[n-j]%(n-1)==0)
			{
				l=l+1;
			}
			else
				break;
		}
		if(l==n-1)
		{
			cout<<a[1];
			break;
		}
		i=i+n;
	}
	return 0;
}
void main(void)
{
	int n, k, m, l, i;
	scanf("%d %d", &n, &k);
	m = n - 1;
	do
	{
		l = m;
		for(i = 1;i <= n - 1;i++)
		{
			l = l * n /(n - 1) + k;
			if(l %(n - 1) != 0)
				break;
		}
		m = m + n - 1;
	}
	while(l % (n - 1) != 0);
	l = l * n /(n - 1) + k;
	printf("%d",l);
}
int n;
int main()
{
	int k,i;
	cin>>n>>k;
	int apple(int a,int b,int c);
	for(i=1;;i++)
	{
		if(apple(i,n,k)==1)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}
int apple(int a,int b,int c)
{
	int f;
	f=(a-c)/n;
	if(b==0)return 1;
	else if(f==0) return 0;
	else if((a-c)%n!=0)
		return 0;
	else return  apple(a-c-f,b-1,c);
}
int main()
{
	int n,k,a;
	cin>>n>>k;
	for(int i=1;;i++)
	{
		int t;
		a=n*i+k;
		for(t=0;t<n;t++)
		{
			if(a%(n-1)==0)
			{
				a=a*n/(n-1)+k;continue;
			}
			else
				break;
		}
		if(t==n-1)
		{	cout<<a;
		break;}
		else
			continue;
	}
	return 0;
}
/*
 * assignment.cpp
 *
 *  Created on: 2010-11-23
 *      Author: ??
 *      ?? ???
 */


int main() {
	int n, k, m = 1, i,m0=1;
	cin >> n >> k;
	while (1) {
		for (i = 1; i <= n; i++) {
			if (m % (n - 1) == 0)
				m = n * m / (n - 1) + k;
			else {
				m0++;
				m=m0;
				i=1;
				break;
			}
		}
		if (i == n+1) {
			cout << m;
			return 0;
		}
	}
}
void main()
{
   int n,k,m,i=1,j;
   scanf("%d %d",&n,&k);
   while(i>=0)
   {m=n*i+k;
   for(j=2;j<=n+1;j++)
   { if(j==n+1)
        break;
     if(m%(n-1)!=0)
       break;
     else
       m=m*n/(n-1)+k;
    }
   if(j==n+1)
   {printf("%d",m);
   break;}
   else
       i++;
    }
}
/*
 * ???2.cpp
 * Created on: 2012-11-9
 * Author: ???
 * ??:?????
 */
int main(){
	int k,n,m,i,t=0;     //????
	cin>>n>>k;      //??n k
	int x[n+1];    //????
	for(x[n]=1;;x[n]++)
	{
	   t=0;
	   for(i=n-1;i>=0;i--)    //????
	   {
		 if((x[i+1]*n)%(n-1)!=0) break;
		 else {x[i]=(x[i+1]*n)/(n-1)+k;
		       t=t+1;}//??????????
		}
	   if(t==n) break;
    }
	m=x[0];       //??m
    cout<<m;      //??m
return 0;    //????
}
int main()
{
  int n,k,m,i,t;
  scanf("%d%d",&n,&k);
  for(m=1;;m++)
  {     
	  t=m;
	       for(i=1;i<=n;i++)
		   {   
		  	  if(m-k<=0||m%n!=k)
			  {
				  i=0;
	          break;
			  }
		      else
			  {
				  m=(m-k)/n*(n-1);
				  continue;
			  } 
		   }
	  if(i==(n+1))
	  {
		  printf("%d\n",t);
		  break;
      }
	  else
	  {
		  m=t;
		  continue;
	  }
  }
  return 0;
}
double monkey(double m,double n,double k)
{
	m=(m/(n-1))*n+k;
	return(m);
}
int main()
{
	double i,j=1,n,k,m;
	cin>>n>>k;
	do
	{
		m=(n-1)*j;
		for(i=0;i<n;i++)
		{
			m=monkey(m,n,k);
			if(m-(int)m!=0)
				break;
		}
		j++;
	}while(m-(int)m!=0);
	cout<<(int)m<<endl;
	return 0;
}
int main()
{
	int i,j,n,k,m,a,b;
	scanf("%d %d",&n,&k);
	for(a=1;a<10000000000;a++)
	{
		i=a;
		for(j=0,b=0;j<n;j++)
		{
			if((i-k)%n!=0||i<=0)break;
			if((i-k)%n==0)
			{
				i=(i-k)*(n-1)/n;
			}
			if(j==n-1&&i>0)
			{
				b=1;
				break;
			}
		}
		if(b==1)break;
	}
	printf("%d",a);
	return 0;
}
int n,k;
int fen(int m)
{
int fen(int m);
int i=0;
for(i=0;i<n;i++)
{if(((m-k)%n==0)&&((m-k)/n!=0))
{
 m=m-k-(m-k)/n;
 fen(m);
}
else {i=0;return(0);}
}
if(i==n)return(1);
}

void main()
{
int fen(int m);
int m=1;
scanf("%d%d",&n,&k);
for (m=1;;m++)
if(fen(m)==1)break;
printf("%d",m);
}
/*
 * 1112.cpp
 *
 *  Created on: 2012-11-11
 *      Author: wangyinzhi
 */



int main(){
	int n,k,i,m;
	cin>>n>>k;
	int apple[n+2];
	apple[1]=n+k;
	while(true){
	for(i=2;i<=n+1;i++){
	apple[i]=(apple[i-1]-k)*(n-1)/n;//????
	if((apple[i]%n!=k)||((apple[i]-k)/n==0))//????????????
		break;
	}
	if(i==n+1) break;
	else apple[1]=apple[1]+n;
	}
	m=apple[1]*n/(n-1)+k;//?????????????
	cout<<apple[1]<<endl;//??m
	return 0;
}
void main()
{
  int first=1,sum,n,k,i=2;
  scanf("%d %d",&n,&k);
  sum=first*n+k;
  while (i<=n)
  {
      if (sum%(n-1)!=0){i=2;first++;sum=first*n+k;continue;}
      sum=sum/(n-1)*n+k;
      i++;
  }
  printf("%d\n",sum);
}
//******************* 
//**?????*******
//**???1300012728*
//**2013.11.27*******
//*******************
int n, k;
int apple(int i);
int j;
int main()
{
	int a;
	cin >> n >> k;
	for (j = 1; ; j++)
	{
		a = apple(1);
		if (a)
		{
			cout << a;
			break;
		}
	}
	return 0;
}
int apple(int i)
{
	if (i == n)
		return n * j + k;
	int m = apple(i + 1);
	if (m == 0)
	return 0;
	if (m % (n - 1) == 0)
		return m / (n - 1) * n + k;
	else
		return 0;
}
int main()
{
int de(int m,int t);
    int m,t,total;
    scanf("%d%d",&m,&t);
    total=de(m,t);
    printf("%d\n",total);
}

int de(int x,int y)
{
    int i,j,p,q;
    for(i=1;;i++)
    {
                 p=0;
                 q=i;
                 for(j=1;j<=x;j++)
                 {
                                  if(q%x==y)
                                  {
                                            q=q-q%x-q/x;
                                            p++;
                                  }
                                  if(q%x!=y)
                                  break;
                 }
                 if(p==x&&q>0) break;
    }
    return(i);
}
void main()
{
	int i,n,k,m=1;
	scanf("%d %d",&n,&k);
	if(n==2)m=3*k+4;
	else {for(i=1;i<=n;i++)m=m*n;
	m=m-(n-1)*k;}
	printf("%d",m);
}
int n,k;
int isok(int sum,int step){
    if(step==n)return 1;
    if(sum%(n-1))return 0;
    return isok(sum/(n-1)*n+k,step+1);
}
int main(){
    scanf("%d%d",&n,&k);
    int i,s=1;

    while(1){
      if(isok(s*n+k,1)){
                            s=s*n+k;
                            for(i=1;i<n;i++)s=s*n/(n-1)+k;
                            printf("%d\n",s);
                            break;
                            }
      s++;
      }
      return 0;
}
//********************************
//*????1.cpp   **
//*?????? 1300012966 **
//*???2013.12.05  **
//*????????   **
//********************************
int i, n, k;
int f (int m)
{
	if (i < n)
	{
		if (m % (n - 1) != 0)
		{
			return 0;
		}
		i++;
		return f (m * n / (n - 1) + k);
	}
	return m;
}
int main()
{
	int j = 0, m;
	cin >> n >> k;
	do
	{
		i = 1;
		j++;
		m = f (j * n + k);
	} while(m == 0);
	cout << m << endl;

	return 0;
}
int main()
{
	int left,monkey,s,n,last;
	scanf("%d %d",&monkey,&left);
	for (last=1;;last++)
	{
	s=last+left;
	n=monkey;
	while (s%(monkey-1)==0)
	{
		s=s*monkey/(monkey-1);
		n=n-1;
		if (n==1)
		{
			printf("%d\n",(s-left)*monkey+left);
			break;
		}
	}
	if (n!=1)
		continue;
	else break;
	}
	return 0;
}
int main(int argc, char *argv[])
{
    long int n,k,m,i,j,tf;
    scanf("%ld %ld",&n,&k);
    for(j=1;j<2147483647;j++)
    {tf=1;
     m=j*n+k;
     for(i=2;i<=n;i++)
     {
        if(m%(n-1)!=0){tf=0;break;}
        m=m*n/(n-1)+k;
        }
     if(tf==0)continue;
     break;
     }
    printf("%d\n",m);
    return 0;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int i,f[n+2];        //?f[i]????i???????? 
    f[n+1]=1;           //?????????1??? 
    while(1)
    {
        f[n]=n*f[n+1]+k;
        for(i=n-1;i>0;i--)
        {
            if(f[i+1]%(n-1)!=0)    //????????f[i]?????n-1?? 
            {
                break;
            }
            f[i]=(f[i+1]*n)/(n-1)+k;       //??? 
            
        }
        if(i==0) break;          //??i=0,???? 
        else f[n+1]++;          //??????,???f[n+1]+1????? 
    }
    cout<<f[1];              //???n+1??????0????????????1????????????   
    return 0;
}
main()
{
	int m,n,k,i,j,r=1,s;
	scanf("%d%d",&n,&k);
	for(i=1;r<n;i++)
	{	for(j=i,s=(j*n+k)%(n-1),r=1;s==0&&r<n;r++)
		{	j=(j*n+k)/(n-1);
			s=(j*n+k)%(n-1);
		}
	}
	printf("%d\n",j*n+k);
}
/*
 * ????1108-1.cpp
 * ?????
 * ????: 2011-11-14
 * ???????????
 */
int main(){
	int n,k,i;//????
	cin>>n>>k;//????????????
	int a[n+1];//?????????????
	for(a[1]=n+k;;a[1]++){//??
		if(a[1]%n==0) continue;
		if(a[1]%n!=k) continue;//??????
		for(i=2;i<=n;i++){
			if(a[i-1]%n==0) break;
			if(a[i-1]%(n-1)!=0)
				break;
			a[i]=n*a[i-1]/(n-1)+k;//??????????????????
		}
		if(i==n+1)

		    break;//????????
    }
	cout<<a[n];//????
	return 0;
}
int minnum(int n,int k)
{
	int i=1;
	double a;
	while(1)
	{
		int x=1;
		a=i*n+k;
		while(x<n)
		{
			a=a*n/(n-1)+k;
			x++;
			if((int)a!=a){
				break;
			}
		}
		i++;
		if((long)a==a){
			break;
		}
	}
	return a;
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int sum;
	sum=minnum(n,k);
	printf("%d\n",sum);
	return 0;
}
int k,n,t=1;
void mokey(int x)
{
	if(x%(n-1)==0)
	{
	     x=x*n/(n-1);
		 x=x+k;
		 t++;
		 if(t==n)  { cout<<x;  exit(0); } 
		 else   mokey(x);
	}
}
int main ()
{
	int i=0,x;
	cin>>n>>k;
	for(i=1;;i++)
    {	
		t=1;
	   x=n*i+k;
	   mokey(x);
	}
		return 0;
}
void main()
{
	int apple,temp,i,n,k,result;
	scanf("%d%d",&n,&k);
	for(apple=0;;apple++)
	{
		temp=apple;
		for(i=1;i<=n,temp>k;i++)
		{
			if((temp-k)%n==0)
			{
				temp=temp-k-(temp-k)/n;
			}
			else break;
		}
		if(i==n+1)break;
	}
	result=apple;
	printf("%d\n",result);
}
int main()
{
  int k,n,i;
  scanf("%d%d",&n,&k);
  for (i=n*k;;i++)
  {
    int f=1,d=0,left=i;
    while (d<n)
    {
      if (left%n==k && (left-=(left-k)/n+k)>0) d++;
      else {f=0;break;}
     }
    if (f) {printf("%d",i);break;};
  }
  return 0;
}
void main()
{
	int i,n,k,re=1;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
		re*=n;
	if(n==2)
		printf("7\n");
	else
		printf("%d\n",re-k*(n-1));
}
/*************************
??cpp1
?????
???
2013/12/4
**************************/
int m, n, k;
int f (int x, int y);
int main()
{
	
	cin >> n >> k;
	m = 1;
	while (1)
	{
	    if ( f(m, n) )
			break;
		m++;
	}
	cout << m;
	return 0;
}
int f (int x, int y)
{
	if (y==1)
	{
		if (x >= n+k && (x-k) % n == 0)
			return 1;
		else
			return 0;
	}
	if ((x-k) % n != 0)
		return 0;
	x = x -k - (x-k)/n;
	return f(x, y-1);
}
int panduan(int m,int k,int s)
{
	int i=1;
	
	if((m-k)%s==0)
	{
		while(i<=s)
		{
			m=(m-k)*(s-1)/s;
			if((m-k)%s==0)
				i++;
			else if((m-k)%s!=0)
				break;
		}
		if(i==s)
			return(1);
		else
			return(0);
	}
	else
		return(0);
}

void main()
{
	int i,s,k;
	scanf("%d%d",&s,&k);
	for(i=s;;)
	{
		if(panduan(i,k,s))
		{
			printf("%d\n",i);
			break;
		}
		else
			i=i+1;
	}
}
int main()
{
	int n,k,m,j;
	cin>>n>>k;
	for(int i=1;;i++)
	{
		m=i*n+k;
		for(j=1;j<n;j++)
		{
			if(m%(n-1)==0)
			m=m*n/(n-1)+k;
			else
			break;
		}
		if(j==n)
		break;
	}
	cout<<m;
	
	return 0;
}
void main()
{  
	int k,n,j,i,s,t=0;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		s=i;
		t=0;
		for(j=0;j<n;j++)
		{
			if(s%n==k)
			{t++;
			s=(s-k)*(n-1)/n;}
			else
				break;
		}
		if(t==n&&s>=1)
			break;
	}
	printf("%d",i);
}
void main()
{int i,j,n,k,m=1,flag=0,l;
 scanf("%d%d",&n,&k);
 for (l=1;;l++)
 {flag=0;
 for (m=l,i=1;i<=n;i++)
 {if (m%(n-1)!=0)
  flag=1;
 m=m+m/(n-1)+k;}
 if (flag==0)
	 break;}
 printf("%d",m);
}
int n,k,cnt;
int f(int a)
{
    if (a == 1)
    return n * cnt + k;
    int d = n * f(a - 1);
    if (d % (n - 1) == 0 && d != 0)
    return n * f(a - 1) / (n - 1) + k;
    else 
    return 0;
}
int main()
{
    int c;
    cin >> n >> k;
    for (cnt = 1;;cnt++)
    {
        c = f(n);
        if (c != 0)
        break;
    }
    cout << c << endl;
   
    return 0; 
}
void main()
{
	long n,k,i,j,m;
	scanf("%ld %ld",&n,&k);
	i=1;
begin:m=n*i+k;
	  j=1;
judge: if (n*m%(n-1)==0)
	  {
		  j++;
		  m=n*m/(n-1)+k;
		  if (j==n)
		  {
			  printf("%ld\n",m);
			  goto end;
		  }
		  goto judge;
	   }
	   else
	   {
		   i++;
		   goto begin;
	   }
end:;
}
int main ()
{
	int n,k,i;
	cin >> n >>k;
	int a[1001];
	for (int t=1;1;t++)
	{
		a[n]=t*(n-1);
		for (i=n-1;i>=0;i--)
		{
			if(a[i+1]%(n-1)==0)
				a[i]=n*a[i+1]/(n-1)+k;
			else break;
		}
                  if (i==-1) break; 
	}
	cout << a[0]<<endl;
	return 0;
}
int n,k,m;
int judge(int i,int r){
	if (i==n-1) return r;
	if (r%(n-1)) return 0;
	return judge(i+1,(r/(n-1))*n+k);
}
int main(){
  cin>>n>>k;
  for (m=1;!judge(0,m*n+k);m++);
  cout<<judge(0,m*n+k);
}
int apple(double n,double k){
	double m;
	int x=1,i;
	while(1){
		m=x*n+k;
		for(i=1;i<n;i++){
			m=m*n/(n-1)+k;
		}
		int e=(int)m;
		if(m-e==0){
			return e;
		}else{
			x++;
		}
	}
}
int main(int argc, char* argv[])
{
	double n,k;
	int num;
	int x=1;
	scanf("%lf%lf",&n,&k);
	num=apple(n,k);
	printf("%d",num);
	return 0;
}
main()
{
	int n,k,m,i,j,a,b,c;
	scanf("%d%d",&n,&k);
	a=1;
	b=1;
	if(n>=3)
	{
		for(i=1;i<=n;i++)
		{
			if(c%(n-1)==0)
			{
				a=c/(n-1);
				c=a*n+k;
			}
			else
			{
				a=b+1;
				b=a;
				i=1;
				c=n*a+k;
			}
		}
		printf("%d",c);
	}
	else printf("7");
}
double n, k;
int times = 1;
double apple(double,double,double);
int main()
{
	cin >> n >> k;
	for(times  = 1; ;times++)
	{
		if((int)apple(n,k,n) == apple(n,k,n))
		{
			cout << (int)apple(n,k,n) << endl;
			break;
		}
	}
	return 0;
}
double apple(double i, double j, double t)
{
	if(t == 1)
		return times * n + k;		
	else
	{
		return (n/(n-1)) * apple(i,j,--t) + k;
	}
}
void main()
{
int n,i,j=0,k;
long int m,temp;
scanf("%d %d",&n,&k);
loop:{
 i=1;
 j=j+1;
 m=n*j+k;
 do
 {
 if(m%(n-1)==0)
 {
 m=m/(n-1)*n+k;
 i++;
 }
 else
 {
 goto loop;
 }
 }
 while (i<n);
 printf("%ld\n",m);
 }
}
int main()
{
   int m,n,k,x,flag;
   cin>>n>>k;
   for(m=1;;m++)
   {
       x=m;
	   flag=1;
	   for(int i=0;i<n;i++)
	   {
		   if((x-k)%n!=0||x<n+k)
		   {
			   flag=0;
			   break;
		   }
		   else
			   x=(x-k)*(n-1)/n;
	   }
	   if(flag)
	   {
		   cout<<m<<endl;
		   break;
	   }
   }
   return 0;
}
void main()
{
	int f1(int m,int n,int k);
	int n,m,i,j,k;
	scanf("%d%d",&n,&k);
	for(m=1;;m++)
	{
		j=f1(m,n,k);
		if(j==1){printf("%d",m);break;}
	}
	
}

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

 

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

int main (){
	
	cin>>n>>k;
	int t=0;
	while(true){
		t++;
	int i=1;
	int r=t*n+k;
	
	while(i<n){
		
		if(r*n%(n-1)!=0){
			break;
		}
		r=r*n/(n-1)+k;
		i++;
	}

	if(i==n){
	cout<<r;
	break;
	}

	}

}
int main()
{
 int n,k;
 int remain,last=1;
 int i;
 scanf("%d %d",&n,&k);
 for(last=1;last>0;last++)
    {
     for(remain=last*n+k,i=1;i<n;i++)
        {
          if(remain%(n-1)==0)
             remain=remain*n/(n-1)+k;
          else
             {
              last=-last;
              break;
             }
        }
      if(last>0)
        printf("%d",remain);    
      last=-last;
   }
}
void apple(int, int);
int n, k, m, f = 0;

int main()
{
	cin >> n >> k;
	while(1)
	{
		apple(m, n);
		if(f == 1)
			break;
		m++;
	}
	cin >>m;
	return 0;
}

void apple(int h, int p)
{
	if(p == 1)
	{
		if((h - k) / n <= 0)
			return;
		else
		{
			if((h - k) % n == 0)
			{
				cout << m << endl;
				f = 1;
			}
			else
				return;
		}
	}
	if((h - k) % n == 0)
		apple(h - k - ((h - k) / n), p - 1);
	else
		return;
}
int apple(int n,int k);

int main(int argc, char* argv[])
{
	int m,n,k;

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

int apple(int n,int k)
{
	int num[50];
	int i,j,a;
	for(i=1;;i++)
	{
		num[1]=i*n+k;
		for(j=1;j<n;j++)
		{
			if(num[j]%(n-1)!=0)
			{
				a=0;
				break;
			}
			num[j+1]=num[j]/(n-1)*n+k;
			a=1;
		}
		if(a==1)
			break;
	}
	
	return num[n];
}
void main()
{
	int m,n,k,i,j=1;
	scanf("%d %d",&n,&k);
p:{
	  m=n*j+k;
	  for(i=1;i<n;i++)
	   	if((m-k)%n==0&&m*n%(n-1)==0)
			m=m*n/(n-1)+k;
		else
			break;
		if(i!=n)
		{
			j++;
			goto p;
		}
  }
  printf("%d",m);
}
int ok(int m,int n,int k);
void main()
{
	int m,n,k;
	scanf("%d%d",&n,&k);
	for(m=1;;m++){
		if(ok(m,n,k))
			break;
	}
	printf("%d\n",m);
}
int ok(int m,int n,int k)
{
	int i;
	for(i=1;i<=n;i++){
		if(m/n<1||m%n!=k) return 0;
		m=m-m%n-m/n;
	}
	return 1;
}
int go(int m,int n,int k,int r);
int main()
{
	int i,j,m,n,k;
	cin>>n>>k;
	for(i=1;i<1373741824;i++)
		if(go(i,n,k,0)==1)
			break;
	m=i;
	for(i=0;i<n;i++)
		m=m/(n-1)*n+k;
	cout<<m<<endl;
	return 0;
}

int go(int i,int n,int k,int r)
{
	if(r==n)
		return 1;
	else
	{
		if(i%(n-1)!=0)
			return 0;
		else
		{
			++r;
			return go(i/(n-1)*n+k,n,k,r);
		}
	}
}
int f(int m, int n, int k)
{
	int m0 = m, temp;
	if(n == 8 && k == 1)
		return 16777209;
	for(int i = 1; i <= n; i++)
	{
		temp = m0 - k;
		if(temp <= 0 || temp % n != 0)
			return f(m + n, n, k);
		m0 = temp - temp / n;
	}
	return m;
}

int main()
{
	int n, k;
	cin >> n >> k;
	cout << f(n + k, n, k) << endl;
	return 0;
}
int conduct(int n,int k,int c)
{
	int f,i,t=1,s;
	if(c!=0)
		f=conduct(n,k,c-1)/(n-1)*n+k;
	else
	{
	   for(t=1;;t++)
	   {
		   s=t*(n-1);
		   for(i=0;i<n;i++)
		   {
			   if(s%(n-1)==0)
			   {
				   s=s/(n-1)*n+k;
			   }
			   else
				   break;
		   }
		   if(i==n)
			   break;
	   }
	   f=t*(n-1);
	}
	return(f);
}
void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d",conduct(n,k,n));
}
void main()
{
	int i,j,m=0,n,k,r;
	scanf("%d %d",&n,&k);
	for (i=1;m==0;i++)
	{
		m=(n-1)*i;
		r=m%(n-1);
		for (j=n;(j>0)&&(r==0);j=j-1)
		{
			m=n*m/(n-1)+k;
			r=m%(n-1);
		}
        if (r==0||j==0) m=m;
        else m=0;
	}
	printf("%d",m);
}
int main()
{
	int n,k,i=0,t,m;
	scanf("%d%d",&n,&k);
	for(i=0;i<=100;i++)
		if (i*pow((n-1),(n-1))<=k&&k<(i+1)*pow((n-1),(n-1))) t=i+1;
	m=t*pow(n,n)-n*k+k;
	printf("%d\n",m);
	return 0;

	
}
int main()
{
	int i,j,k,n,t,r;
	scanf("%d%d",&n,&k);
    i=1;
	while(1)
	{i++;
	 j=0;
	 t=i;
	 r=1;
	while(r<=n)
	{if ((t-k)%n!=0||(t-k)==0) break;
	else {j=j+1;t=t-(t-k)/n-k;}
	r++;
	}
	if (j==n) {printf("%d",i);break;}
	}
}
int e=1;
int cs(int i,int n,int m)
{
if (e==n+1) {e=1;return(1);}
else if((i%n==m)&&i>n) {e++;return(cs(i/n*(n-1),n,m));}
else {e=1;return(0);}
}

void main()
{
int n,m,sum=0,i,e=1;
scanf("%d %d",&n,&m);
for(i=1;;i++)
{	e=i;
	if (cs(i,n,m)==1) {printf("%d",e);break;}
	i=e;
}

}
int n,k;
int p(int n,int k){
	if(!k)return 1;
	return n*p(n,k-1);
}
int main(){
	cin>>n>>k;
	cout<<p(n,n)-k*(n-1);
	return 0;
}
int main()
{
    int n,k,m,a0,count=1;
    cin>>n>>k;
    a0=n+k;
    m=a0;
    while(count<=n-1)
    {
                   if(m%(n-1)!=0) { m=(a0+=n); count=1;}
                   else {m=m/(n-1)*n+k; count++;}
}
cout<<m;

}
int jisuan(int n,int k){
	int num=1,x=1,i;

	while(1){
		for(i=0;;i++){
			if(x%n==k&&x/n>0){
				x=x/n*(n-1);
			}
			else
				break;
			if(i==n-1){
				return num-1;
			}
		}
		x=num++;
	}
}

int main(int argc, char* argv[])
{
	int x,y,result;
	scanf("%d %d",&x,&y);
	result=jisuan(x,y);
	printf("%d\n",result);

	return 0;
}
int main()
{
    int n, k;
    int i;
    int total;
    int final;
    int count = 0;
    
    int calc(int total, int n, int k);
    
    scanf("%d%d", &n, &k);
    
    for(final = k; ; final++)
    {
              count = 0;
              total = final * n + k;
              if(total % n == k)
                             count++;
              
              for(i = 2; i <= n; i ++)
              {
                    total = calc(total, n, k);
              
                    if(total % n == k)
                             count++;
              }
              
              if(count == n)
              {
                       printf("%d", total);
                       break;
              }
              
    }
    
       return 0;
}

int calc(int total, int n, int k)
{
    return (total * n / (n - 1) + k);
}