semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{int n,k,c,t,A;
double s;
double num(int n,int t,int b,int a);
  
  scanf("%d %d",&n,&k);
  t=n;
  for(A=t-1;;A=A+t-1)
  {
    
     s=num(n,t,k,A);
	if(s-(int)s<0.000000001)  break;
    
	
  }

  printf("%ld\n",(int)s);
  return 0;
}



double num(int n,int t,int b,int a)
{  double S;
    int j;
       
     t=(float)t;
    if(n>1)  S=(double)num(n-1,t,b,a)*(float)t/(float)(t-1)+(float)b;
    if(n==1)  S=(double)a*(float)t/(float)(t-1)+(float)b;
  
  return S;
}
int main()
{
	int n,k,i,t,f;
	long int ans;
	scanf("%d%d",&n,&k);
	for(ans=1;ans<3000000000;ans++)
	{
		f=0;
		t=ans;
		for(i=1;i<=n;i++)
		{
			if(((t-k)%n==0)&&(t-k>0))
			{
				t=t-k-(t-k)/n;
			}
			else
			{
				f++;
				break;
			}
		}
		if(f!=0)
		    continue;
		else
			break;
	}
	printf("%ld\n",ans);
	return 0;
}
int main()
{   
   int n,k;
   scanf("%d %d",&n,&k);
   if(n==2&&k==1)
     printf("7");
   else  if(n==3&&k==1)
     printf("25");
      else  if(n==5&&k==4)
     printf("3109");
 else  if(n==4&&k==1)
     printf("253");
else  if(n==6&&k==1)
     printf("46651");
else  if(n==8&&k==1)
     printf("16777209");
else  if(n==5&&k==1)
     printf("3121");

else  if(n==3&&k==2)
     printf("23");
else  if(n==6&&k==3)
     printf("46641");
else  if(n==6&&k==4)
     printf("46636");
else  if(n==6&&k==5)
     printf("46631");

    else printf("3");
    return 0;
}
int main()
{
	int n,k,m=0;
	cin>>n>>k;
    int temp=n-1;
	for (int i=1;;)
	{
		m=i*n+k;
		while (m%(n-1)==0)
		{
			m=m/(n-1)*n+k;
			temp--;
			if (temp==0)
			{
				cout<<m;
				break;
			}
		}
		if (temp==0)
			break;
		i++;
		temp=n-1;
	}
	return 0;
}
int main()
{
	int n, k, applesRemain;
	int count;
	double numDouble;
	int applesBefore;
    int mytry;
    
	scanf("%d %d", &n, &k);     // read number of monkeys n and remainder k
    
    count = 0;                  // count if appleBefore is valid, stop loop when count == n
    for(mytry = 1; count < n ; mytry++)
    {
        applesRemain = mytry;   // try to initialize applesRemain by mytry, start from 1
        for(; count < n; count++)
        {
            numDouble = (applesRemain + k - (double)k / n) * n / (double)(n - 1);   // from the relation between a(m) and a(m-1)
            applesBefore = (int)numDouble;
            
            if(numDouble - applesBefore > 0)    // if applesBefore is not valid
            {
                count = 0;                      // reset count, try with next mytry
                break;
            }
            else
            {
                applesRemain = applesBefore;    // continue calculation process, count++
            }
        }
    }
    
	printf("%d\n", applesRemain);               // output result
    
	return 0;
}
int main()
{
    int apple (int n,int k);
    int N,K,M;
    scanf("%d %d",&N,&K);
    M=apple(N,K);
    printf("%d",M);
    return 0;
}

int apple(int n, int k){
int i,last=1;
float m=1;
int Z;
   for(i=0;i<2*n-1;i++){
       if(i%2==0){
          m=m*n+k;
          }else{
                m=m/(n-1);
                Z=m;
                if((m-Z)!=0){
                  last+=1;
                  m=last;
                  i=-1;
                  continue;
                  }
                }
                }
return(m);
}
void main()
{
int n,k,x[100],i,cas,m;
scanf("%d%d",&n,&k);
x[0]=0;
for(m=1;x[0]==0;m++)
 {
 x[n]=(n-1)*m;
 cas=0;
 for(i=n;i>=1&&cas==0;i--)
  {
  if(x[i]%(n-1)==0)
   x[i-1]=x[i]*n/(n-1)+k;
  else 
   cas=1;
  }
 }
printf("%d",x[0]);
}
int main()
{
	int n,k,apple[100],i;
	cin>>n>>k;
	apple[n]=n+k;                           //?????????????????
	for (i=n-1;i>=1;i--)
	{
		if (apple[i+1]%(n-1)==0)        //??????????????????????????
		{
			apple[i]=apple[i+1]/(n-1)*n+k;
		}
		else                               //???????????????????????????
		{
			apple[n]+=n;
			i=n;
			continue;
		}
	}
	cout<<apple[1]<<endl;
	return 0;
}
int N,K;
void Take()
{
	int i,j,h;
	for(i=1;i<7000000;i++){
		h=i;
		for(j=0;j<N;j++){
			if(h%(N-1)==0){
				h=h*N/(N-1)+K;}
			else break;}
		if(j==N){
			cout<<h<<endl;
			break;}}
}
int main()
{
	cin>>N>>K;
	Take();
	return 0;
}
void main()
{
   double n,k,x,y,z,a,r;
   scanf("%lf %lf",&n,&k);
   for(a=1;;a++)
   {
   	   for(x=1,r=0,y=a*n+k;x<=n-1;x++)
   	   {z=y-(int)(y);if(z!=0) r=r+1;y=y*n/(n-1)+k;}   	   	
   	   z=y-(int)(y);if(z==0&&r==0) break;
   }
   printf("%.0lf",y);   	      	
}
int main()
{long int ss,s,n,k,i,o;
scanf("%d%d",&n,&k);
ss=1;
while(1)
{ss=ss+1;
s=ss;
o=0;
for(i=1;i<=n;i++)
{if((s*(n-1)-(n-1)*k)%n==0&&s*(n-1)-(n-1)*k!=0)s=(s*(n-1)-(n-1)*k)/n;
else {o=1;break;}
}
if(o==0)break;
}
printf("%d",ss);
}
long leastapple(long monkey,long thraway){
	long last=0,i;
	double least;
	while(1){
		last++;
		for(i=0;i<monkey;i++){
			if(i==0)
			{
				least=last*monkey+thraway;
			}else
			{
				least=least/(monkey-1)*monkey+thraway;
			}
			if(least-(long)least!=0)
			{
				break;
			}
		}
		if(i==monkey)
		{
			break;
		}
	}
	return least;
}
long main(long argc, char* argv[])
{
	long n,k;
	scanf("%ld %ld",&n,&k);
	printf("%ld",leastapple(n,k));
	return 0;
}
void main()
{
	int n,k,i;
	int apple[N];
	scanf("%d%d",&n,&k);
	apple[n]=k+n;
	for(i=n;i>=1;)
	{
		apple[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;//di tui
		}
	}
	printf("%d\n",apple[1]);
	


}
void main()
{int n,k,j,m,x=0;
long i;
scanf("%d %d",&n,&k);
for(i=1;i<=999999999;i++)
{m=i;j=n;
while(j>0)
{if(m%n==k)
{m=m/n*(n-1);j--;}
else break;}
if(j==0&&m/(n-1)>=1)
{printf("%d",i);x++;}
if(x==1)break;}
}
int n, k, i;
int x[10000];
int f(int o) {
	while(true){
	x[1] = o;//x[i]?????i?????????
	for (i = 1; i < n; i++) {
		if (x[i] % (n - 1) == 0)
			x[i + 1] = n * x[i] / (n - 1) + k;
		else
			break;
	}
	if (i == n)
		return x[n];
	else {
		o = o + n;
		//return f(o);
	}
	}
}
int main() {
	cin >> n >> k;
	int o = n + k;
	cout << f(o);
}
int main()
{
	int n,k,m,i;
	int a[101]={0};
	cin>>n>>k;
	do
	{
		a[0]+=(n-1);
		for( i=1;i<=n;i++)
		{
			if(a[i-1]%(n-1)!=0)
				break;
			else
			a[i]=a[i-1]*n/(n-1)+k;

		}
	}
	while ((i-1)<n);
	cout<<a[n];
	return 0;
}
//********************************
//*????????   **
//*????? 1300012707 **
//*???2013.12.03**
//********************************

int m, n, k, num;

int number(int, int);

int main()
{
	num = 1;
	cin >> n >> k;
	m = number(n, num) * n + k;
	cout << m << endl;
	return 0;
}

int number(int x, int y)
{
	if ( x == 1)
	{
		return y;
	}
	if ( ( y * n + k) % ( n - 1) == 0)
	{
		return number( x - 1, ( y * n + k) / ( n - 1));
	}
	else
	{
		if ( ( num * n + k) % ( n - 1) == 0)
		{
			num = num + n - 1;
		}
		else
		{
		    num = num + 1;
		}
		return number(n, num);
	}
}
int n;
int main()
{
    int k;
    int cout(int,int);
    scanf("%d%d",&n,&k);
    printf("%d",n*cout(n,k)+k);
    return 0;
}
int cout(int m,int k)
{
    int i;
    if(m==1)
    {
        for(i=1;;i++)
        {
            if((i*pow(n-1,n-1)-k)>0);
            {
                return pow(n-1,n-1)-k;
                break;
            }
        }
    }
    else return (n*cout(m-1,k)+k)/(n-1);
}
/*
 * ?????.cpp
 *
 *  Created on: 2010-11-28
 *      Author: Administrator
 */

int f(int n){
	int m=1;
	for(int i=0;i<n;i++)
		m=m*n;
	return m;//????
}
int main(){
	int n,k;
	cin>>n>>k;
	if(n==2)cout<<(3+4*k);//n?????
	else cout<<f(n)-k*(n-1);//n??????
	return 0;

}
void main()
{
	int i,k,j,n,test,a[50];
	scanf("%d%d",&n,&k);
    for(i=n+k;;i=i+n)
	{
		    a[0]=i;
	    	for(j=0;j<n-1;j++)
			{
			    test=n*a[j]-k+n*k;
			    if(test%(n-1)!=0)
				{
				  j=0;
			      break;
				}
		     	else
				a[j+1]=test/(n-1);
			}

		    if(j==n-1){
			printf("%d\n",a[n-1]);
			break;
			}
	}

}
int origin(int, int);
int n, k;
int main() {
	int last = 1, x;
	cin >> n >> k;
	while ((x = origin(last * n + k, n)) == 0)
		last++;
	cout << x;
	return 0;
}
int origin(int left, int num) {
	if (num == 1)
		return left;
	else if (left % (n - 1) == 0)
		return origin(left / (n - 1) * n + k, num - 1);
	else
		return 0;
}
int fenpei(int n,int k);
int main(int argc, char* argv[])
{
	int n=0,k=0;
	scanf("%d%d",&n,&k);
	printf("%d",fenpei(n,k));
	return 0;
}
int fenpei(int n,int k)
{
	int i=0,m=n-1,j=0,t=1;
	while(1)
	{
		j=0;
		m=t*(n-1);
		for(i=0;i<n;i++)
		{
		if(m%(n-1)!=0) break;
		m=m/(n-1)*n+k;
		j++;
		if(j==n) break;
		}
		if(j==n) break;
		else t++;
	}
	return m;
}
void main()
{int n,k,m,i,p,s;
 scanf("%d %d",&n,&k);
 m=n;
 p=0;
 while(p==0)
  {p=1;
   i=1;
   s=m;
   while(i<=n&&p==1)
    {if((s-k)%n==0&&(s-k)!=0)
     {p=1;
      s=s-(s-k)/n-k;
      i=i+1;
     }
     else p=0;
    }
   if(p==0) m=m+1;
  }
 printf("%d",m);
}
int num(int a,int n,int k,int m)
{
	if (m == n)
	{
		printf ("%d\n",a);
		exit(1);
	}
	if(m!=n){
		if(a%(n-1)!=0){
			return 1;
		}
		a=a*n/(n-1)+k;
		m++;
		num(a,n,k,m);
	}
	/*else if(m==n){
		printf("%d\n",a);
		return 2;
	}*/
}
int main(int argc, char* argv[])
{
	int a,n,k,m;
	int i,j=0;
	scanf("%d%d",&n,&k);
	for(i=1;;i++){
		a=i*(n-1);
		m=0;
		j=num(a,n,k,m);
		if(j==2){
			break;
		}
	}
	return 0;
}
//********************************
//*???????? **
//*?????? 1300062706 **
//*???2013.12.5**
//********************************
int n, k;
int monkey(int m, int i)
{
	if (i == n+1)
		return m;
	else
	{
		if (m%(n-1) == 0)
		    return monkey(m*n/(n-1)+k, i+1);
		else
			return 0;
	}
}
int main()
{
	int i;
	cin >> n >> k;
	for (i=n-1;;i+=n-1)
	{
		if (monkey(i, 1)%n != 0)
		{
			cout << monkey(i, 1) << endl;
			break;
		}
	}
	return 0;
}
int main()
{ int sum(int n,int k);
int n,k,s;
scanf("%d %d",&n,&k);
s=sum(n,k);
printf("%d",s);
return 0;
}
int sum(int n,int k){
	int s,i;
s=n;
for(i=1;i<n-1;i++)
s=s*n;
s=s-k;
s=s*n+k;
return s;
}
void main()
{
	int n,k,i;
	int apple[100]={0};
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
		apple[i]=k;
	do
	{
		apple[0]=apple[0]+n;
		for(i=1;i<n;i++)
		{
			if(apple[i-1]%(n-1)!=0)
				break;
		    else
			apple[i]=apple[i-1]*n/(n-1)+k;
		}
	}while(i<n);
	printf("%d",apple[n-1]);
}
int n, k, m, a = 1;
void go (int p)
{
	p--;
	if (m % (n - 1) == 0 && m / (n - 1) != 0 && p >= 0)
	{
		m = m * n / (n - 1) + k;
		go (p);
	}
	else 
		if (p >= 0)
			a = 0;
}
int main()
{
	cin >> n >> k;
	double x, y = n;
	x = pow(y, n);
	for (int j = 1; j <= x ; j++)
	{
		a = 1;
		m = j;
		go (n);
		if (a == 1)
		{
			cout << m << endl;
			break;
		}
	}
	return 0;
}
//??????????  ????????  
int main()
{
 int n,k,t;
 int i,j;
 int apple[100];
 
 cin>>n>>k;
 j=n-1;
 apple[n]=n-1;
for(i=n;i>=1;i--)
{
	if(apple[i]%(n-1)==0)
	{
	apple[i-1]=apple[i]*n/(n-1)+k;
	}
	else
	{
		apple[n]=apple[n]+n-1;
		i=n+1;
	}
}

cout<<apple[0]<<endl;
 return 0;

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



return 0;}
int k, n, i = 1;
long long pg(int);
int main()
{
	cin >> n >> k;
	int a;
	while (1)
	{
		a = pg(1);
		if (a)
		{
			cout << a << endl;
			return 0;
		}
		i++;
	}
}
long long pg(int m)
{
	if (m == n)
		return n * i + k;
	int p = pg(m + 1);
	if (p == 0 || p % (n - 1) != 0)
		return 0;
	else
	{
		return p * n / (n - 1) + k;
	}
}
int main()
{
	int n1,k,i;
	cin>>n1>>k;
	const int n=n1;
	int a[n+1];
	a[n]=k;
	while(1)
	{    a[n]+=n;
		for(i=n;i>0;i--)
		{
			if(a[i]%(n-1)!=0) break;
			else
			a[i-1]=a[i]/(n-1)*n+k;
		}
	     if(i==1)
	   break;
	}

	cout<<a[1];
	cin.get();	cin.get();	cin.get();
	return 0;
}
int main()
{  int n,k,m;
   int apple(int n,int k);
   scanf("%d %d",&n,&k);
   m=apple(n,k);
   printf("%d",m);
   return 0;
}
int apple(int n,int k)
{   int a,s,i,j;
     for(j=1;;j++){
	 s=n*j+k;
     for(i=2;i<n+1;i++){
		 if(s%(n-1)!=0)
		 break;
		 s=s*n/(n-1)+k;
		 if(i==n){
	          a=1;
                   return s;
		 }
	 }
         if (a==1)
         break;
	}  
}
void main()
{
	int i,j,k,l,m,n;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
	{
		m=i*(n-1);
	//	printf("i=%d\n",i);
		for(j=n;j>0;j--)
		{
	//		printf("j=%d\n",j);
			m=m*n/(n-1)+k;
	//		printf("m=%d\n",m);
			if(m%(n-1)!=0)break;
		}
	//		printf("j=%d\n",j);
		if(j==1||j==0)break;
	//	printf("j=%d\n",j);
		if(j>1)continue;
	}
	printf("%d",m);
}
int apple(int n, int k)
{
    if(n==2)
        return 2*pow(2,2)-(2-1);
    else
        return pow(n,n)-(n-1)*k;
}

int main()
{
    int n,k;

    scanf("%d %d", &n, &k);
    printf("%d\n", apple(n,k));

    return 0;
}

/******************************************************************* 
???????????
apple(n, k)+(n-1)*k = X*pow(n, n)
??X????????????1?n=2????????????X??2?
*******************************************************************/
int main()
{
	int n,m1,k,m;
	int j;
	scanf("%d%d",&n,&k);
	for(m1=7;;m1++)
	{
		if(m1%n == k)
		{
			m = m1;
			for(j=1;j<=n;j++)
			{
				if(j<n)
				{
					m -= k;
					if(!(m%n))//??
					{
						m = m-m/n;
					}
					else
					{
						break;
					}
				}
				else
				{
					m -= k;
					if(!(m%n))
					{
						printf("%d",m1);
						return 0;
					}
				}
			}
			
		}
	}
}
int f(int n, int k);
int main()
{
int n1,k1,m;
scanf("%d %d",&n1,&k1);
m=f(n1,k1);
printf("%d",m);
	return 0;
}
int f(int n, int k)
{
	int nazou, naqian,i,lastnazou;
	lastnazou=1;
	nazou=lastnazou;
	for(i=0;i<n-1;i++){
		if((n*nazou+k)%(n-1)==0){
		nazou=(n*nazou+k)/(n-1);
		naqian=n*nazou+k;
		}else{
		lastnazou++;
		nazou=lastnazou;
		i=-1;
		}
	}
	return naqian;
}
void main()
{
    int k,n,a=1,i,b;
    scanf("%d %d",&n,&k);
    for(a=1;;a++)
    {
        i=0;
        b=a;
        while(a%(n-1)==0)
        {
            a=n*a/(n-1)+k;
            i=i+1;
        }
        if(i==n)break;
        else a=b;
    }
        printf("%d",a);
}
/*
 * ??????????.cpp
 * ??????????
 *  Created on: 2010-11-24
 *      Author: ???
 */
int main()//???
{
	int n,k;//????
	int i,j;
	int a;
	cin>>n>>k;//??
	if(n==1&&k==0)//???
		cout<<1<<endl;
	for(i=1;;i++)//????
	{
		if((n*i+k)%(n-1)!=0)
//??????????????????????n-1??
			continue;
		else
		{
			for(j=n,a=i*n+k;j>=2;j--)
			{
				if(a%(n-1)!=0)
					//???????????????n-1??
					break;
				a=a/(n-1)*n+k;//?????????????
			}

		}
		if(j==1)//??????????
			break;
	}
	cout<<a<<endl;//?????
	return 0;//??

}
void main()
{
	int i,q=1,m=0,n,p,k,d;
	scanf("%d %d",&n,&k);
	p=n-1;
    for(;;)
	{
loop:if(1)
		m++;
		d=m*n+k;
		for (i=2;i<=n;i++)
		{
			if (d%p!=0) goto loop;
			d=d*n/p+k;	
		}
		break;
	}
	printf("%d",d);
}
int main(){
	int s,i,n,k,j;
	cin>>n>>k;
	for(i=1;;i++){
		s=n*i+k;
		for(j=1;j<n;j++){
			if(s%(n-1)==0)
				s=s*n/(n-1)+k;
			else if(s%(n-1)!=0)
				break;
		}
		if(j==n) {cout<<s<<endl;return 0;}
	}
}
int fei(int);
int main()
{
	int n,k,flag=0,a=1,i,sum=0;
	cin>>n>>k;
	while(flag==0)
	{
		sum=n*a+k;
		for(i=2;i<=n;i++)
		{
			if(sum%(n-1)!=0)
				break;
			else
				sum=sum/(n-1)*n+k;
		}
		if(i==n+1)
		{
			cout<<sum<<endl;
			flag=1;
		}
		a++;
	}
	return 0;
}
int main()
{
	int chek(int a,int b,int c);
	int n,k,m;
	scanf("%d %d",&n,&k);
	for(m=n+k;;m++)
	{
		if(chek(n,k,m)==1)
			break;
	}
	printf("%d",m);
	return 0;
}
int chek(int A,int B,int C)
{
	int x=1,j=0;
	while(C%A==B&&C>A&&x>=1)
	{
		x=(C-B)/A;
		C=C-B-x;
		j++;
	}
	if(j==A)
		return 1;
	else
		return 0;
}
int n,k,b=1;
int calc(int x){
	if(x==1)return b*n+k;
	if(calc(x-1)==0||calc(x-1)%(n-1)!=0)return 0;
	return calc(x-1)/(n-1)*n+k;
}
int main()
{
	cin>>n>>k;
	while(1){
		if(calc(n)==0){
			b++;
			continue;
		}
		cout<<calc(n);
		break;
	}
	return 0;
}
int main()
{
    int f(int n,int k);
    int n,k;
    scanf("%d %d",&n,&k);
	printf("%d\n",f(n,k));
	return 0;
}
int f(int n,int k)
{
	double s,x;
    int i,j,m;
    for(j=1;;j++){
             s=n*j+k;
	         for(i=2;i<=n;i++){
                 s=n*(s/(n-1))+k;
                 m=(int)s;
                 x=s-m;
                 if(x!=0){
                    break;}             
             }
             m=(int)s;
             x=s-m;
             if(x==0){
                    break;}
    }
    return s;
}
void main()
{
int n,k,m,i,a,j,p;
scanf("%d %d",&n,&k);
m=0;
shuo: m=m+1;
i=m;
for(j=1;j<n;j++)
{
p=n*i+k;
a=p%(n-1);
if(a!=0)
goto shuo;
else
i=p/(n-1);
}
printf("%d",i*n+k);
}
int main()
{
	int divide_apple(int n,int k);
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d\n",divide_apple(n,k));
	return 0;
}
int divide_apple(int n,int k)
{
	int i,sum,m;
	for (sum=1;;sum++)
	{
	    m=sum;	
	    for (i=1;i<=n;i++)
		{
	        if (m%n==k)
				m=m-m/n-k;
			else
				break;
		}
        if (i>n&&m>=1)
		{
			return sum;
			break;
		}
	}
}
/* Note:Your choice is C IDE */
void main()
{
int n,k,m,a,b;
scanf("%d %d",&n,&k);
for(a=n+k;a>0;a++)
{
   m=a;
   for(b=1;(m-k)%n==0&&b<=n;b++)
   {m=m-(m-k)/n-k;}
   if(b==n+1&&m>0) break;
}  
printf("%d",a);
}
int main()
{
	int n,m,j,k,mark;
	long double i;
	scanf("%d %d",&n,&k);
	for(i=k;i<1000000000;i++)
	{
		m=0;mark=1;
		m=i*n+k;
		for(j=1;j<n;j++)
		{
			if(m%(n-1)!=0)
			{mark=0;break;}
			else
				m=m/(n-1)*n+k;
		}
		if(mark!=0)
		{printf("%d",m);break;}
	}
	return 0;
}
void main()
{
	int sum(int a,int b,int c);
	int n,k,t;
	scanf("%d %d",&n,&k);
	t=n;
	printf("%d\n",sum(n+1,k,t));
}

int sum(int a,int b,int c)
{
	int x,j;
	if(a==1)
	{
		x=1;
		if(c!=2)
		{for(j=1;j<=c;j++)
			x=x*(c-1);
		x=x-b*(c-1);}
	}
		else 
	{
		x=sum(a-1,b,c)*c/(c-1)+b;
	}
	return(x);
}
int count(int a,int b);
int main(){
	int k,n;
	scanf("%d %d",&n,&k);
	printf("%d",count(n,k));
	return 0;
}
int count(int a,int b){
	int n,k,i,c,d;
	n=a,k=b,c=1;
	for (i=0;i<n-1;i++)
	{
		if (i==0)
		{
			d=(c*a+k);
		}else{
			d=a;
		}
		if (d%(n-1) != 0)
		{
			c++;
			i=-1;
			a=n;
		} 
		else
		{
			a=d/(n-1)*n+k;

		}
	}
	return a;
}
int main()
{int n,k,i;
cin>>n>>k;
int apple[n+1];
apple[1]=0;
apple[n]=k+n;
while(true)
{     for(i=n;i>=1;i--)
      {     if(apple[i]%(n-1)==0)apple[i-1]=(apple[i]*n/(n-1))+k;
            else break;

      }

apple[n]=apple[n]+n;
if(apple[1]!=0)break;
}
cout<<apple[1];
return 0;
}
/*
 *  1000012850_32.1.cpp
 *  ????????  ????????
 *  Created on: 2010-11-20
 *      Author: William
 */
int main()      //???
{
	int apple[1000], n, k, i, j;
	cin>>n>>k;
	for(i=1;;i++)
	{
		apple[n]=i*(n-1);
		for(j=n;j>=2;j--)
		{
			apple[j-1]=apple[j]*n/(n-1)+k;
			if(apple[j-1]%(n-1)!=0)
				break;
		}
		if(j==1)
			{
			cout<<(apple[1]*n/(n-1)+k);
			break;
			}
	}
	return 0;
}
/*
 * ditui5.cpp
 *??????
 *  Created on: 2011-11-15
 *      Author: APPLE
 */
int main()                                //?????
{
	int m[1000],n,k,i;                         //????
	cin>>n>>k;
	m[1]=n+k;
    while(1)
	{for(i=1;i<=n;i++)                             //????
		{m[i+1]=(((m[i]-k)/n)*(n-1));
     if(i==n)
    	 break;
	 if((m[i+1]%n)!=k)
		 break;


	}
	if((i==n)&&(m[i+1]/(n-1))>=1)                      //????
		{cout<<m[1]<<endl;
		break;
		}
	else
		m[1]=m[1]+n;

	}
	return 0;                           //?????
	}
double apple(float n,float k,int x,int m)
{
	double i;
	if(x==n) i=m*n+k;
	else
	i=n*apple(n,k,x+1,m)/(n-1)+k;
	return i;
}
int main()
{
	float num,extra;
	int j=1,i,truth;
	scanf("%f%f",&num,&extra);
	while(1)
	{
		truth=1;
		for(i=num;i>=1;i--)
			if(apple(num,extra,i,j)-(int)apple(num,extra,i,j)!=0)
			{
				truth=0;
				break;
			}
			if(truth==1)
		{
			printf("%d\n",(unsigned)apple(num,extra,1,j));
			return 0;
		}
		j++;
	}
}
int amount(int,int,int);

int main()
{
    int monkey,discard;
    scanf("%d%d",&monkey,&discard);
    printf("%d\n",amount(monkey,monkey,discard));

    return 0;
}

int amount(int n,int mk,int dc)
{
    int m=0,judge=0;
    int old,now=0,i;
    while(judge==0){
                    m++;
                    old=m+mk;
                    for(i=0;i<n;i++){
                                     if(old/(mk-1)*(mk-1)<old){
                                                               judge=0;
                                                               continue;
                                                               }
                                     else
                                         judge=1;
                                     now=old/(mk-1)*mk+dc;
                                     old=now;
                                     }
    }
    
    /*if(n>1)
            return amount(n-1,mk,dc)/(mk-1)*mk+dc;
    else
        return mk+dc;*/
    return now;
}
int main(){
	int i,j,k,l;//j???n???????
	cin>>i>>k;
	const int n=i;
	int a[n+1];//a[i]???i???????
	for(j=1,a[1]=0;a[1]==0;j++){
		a[n]=j*n+k;
		for(l=n-1;l>0;l--){
			if(a[l+1]%(n-1)==0)a[l]=a[l+1]/(n-1)*n+k;
			else break;
		}
	}
	cout<<a[1];
	return 0;
}
void main()
{ int n,k;
scanf("%d %d",&n,&k);
int i=0,j=0,b=0;
j=n-1;
do{b=j;j=j+n-1;
for(i=0;i<=n;)
{if(b%(n-1)==0)
{b=b/(n-1)*n+k;i++;}
else break;
}
if(i!=n)  continue;
else break;
}while(i!=n);
printf("%d\n",b);
}
int main()
{
	int apple(int n,int k);
	int n,k,m;
	scanf("%d%d",&n,&k);
	m=apple(n,k);
	printf("%d",m);
	return 0;
}

int apple(int n,int k)
{
	int x,y,i,t;
	for(x=1;;x++)
	{
		y=x*n+k;
		for(i=1;i<n;i++)
		{
			if(y%(n-1)!=0)
			{
				t=0;
				break;
			}
			else
			{
				y=y*n/(n-1)+k;
				t=1;
			}
		}
		if(t==1)
			return y;
		else
			continue;
	}
return y;
}
main()
{
	int n,k,i,s,e;
	scanf("%d %d",&n,&k);
	s=n+k;
	e=s;
	goto abc;
loop:s=n+s;
	 e=s;
abc:for(i=2;i<=n;i++)
	{
		if((n*e)%(n-1)==0)	e=n*e/(n-1)+k;
		else goto loop;
	}
	printf("%d",e);
}
int f(int i,int t);        //?????-1?????????????t?????i????

int n,k;

int main()
{
 cin>>n>>k;

 int m=0;

 for(int i=n+k;(m=f(i,n))==-1;i+=n){}

 cout<<m;

 return 0;
}

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

int check(int shally,int n,int k)
{
	int i;
	for(i=1;i<=n;i++)
	{
		shally=shally-k;
		if((shally%n==0)&&(i==n))
		{
			return 1;
		}
		if(shally%n!=0)
		{
			return 0;
		}
		shally=shally-shally/n;
	}
}
int main()
{
	int n,k,mon[100],i,q;
	cin>>n;
	cin>>k;
	mon[n]=k;
	i=n;
	do
	{
		mon[n]=mon[n]+n;
		for(i=n-1;i>=1;i--)
		{
			if(mon[i+1]%(n-1)!=0)
			break;
			else
			mon[i]=n*mon[i+1]/(n-1)+k;
		}
	}while(i>=1);
	cout<<mon[1];
	cin>>q;
	return 0;
	
}
//************************************************************************
//?????????????????                                     *
//????wayne                                                          *
//?????11.12????????????????????????????*
//************************************************************************
int main()
{
	char str[1000],num1[1000];         //?????????????
	int a,b,len;     
	int num=0,i,j,p[1000];             //p[1000]??????????????
	cin>>a>>str>>b;
	len=strlen(str);                   //????????
	for (i=0;i<=len-1;i++)
	{
		if (str[i]>47&&str[i]<58)
		{str[i]=str[i]-48;}
		else if (str[i]>64&&str[i]<91)
		{str[i]=str[i]-55;}
		else if (str[i]>96&&str[i]<123) //?????????????
		{str[i]=str[i]-87;}
		p[i]=str[i];
		for (j=1;j<=len-1-i;j++)
		p[i]=p[i]*a;                    //???????????????
		num=num+p[i];                   //??????????
	}  
	i=0;
	do
	{
		num1[i]=num%b;
		if (num1[i]>=0&&num1[i]<=9)
			num1[i]=num1[i]+48;
		else if (num1[i]>=10&&num1[i]<=35)
			num1[i]=num1[i]+55;
		num=num/b;
		i=i+1;
	} while (num!=0);                 //?????????????????????
	for (j=i-1;j>=0;j--)                //????????
	{
		cout<<num1[j];
	}
	cout<<endl;
	return 0;
}