Problem Type : Ad hoc
#include<stdio.h>
#include<math.h>
unsigned long recurtion(int n,int m)
{
{
int l;
l=n%m;
n=n/m;
if(n>=m && l==0)
{
return n+recurtion(n,m);
}
else if(n>=m && l!=0)
{
return n+ recurtion(n+l,m);
}
else if((n+l)>=m)
{
return n+ recurtion(n+l,m);
}
if(n<m)
{
return n;
}
}
}
int main()
{
unsigned long a,b,sum;
while(scanf("%lu%lu",&a,&b)==2)
{
if(a<b)
{
printf("%lu",a);
}
else
{
sum=recurtion(a,b);
printf("%lu\n",a+sum);
}
}
return 0;
}
#include<stdio.h>
#include<math.h>
unsigned long recurtion(int n,int m)
{
{
int l;
l=n%m;
n=n/m;
if(n>=m && l==0)
{
return n+recurtion(n,m);
}
else if(n>=m && l!=0)
{
return n+ recurtion(n+l,m);
}
else if((n+l)>=m)
{
return n+ recurtion(n+l,m);
}
if(n<m)
{
return n;
}
}
}
int main()
{
unsigned long a,b,sum;
while(scanf("%lu%lu",&a,&b)==2)
{
if(a<b)
{
printf("%lu",a);
}
else
{
sum=recurtion(a,b);
printf("%lu\n",a+sum);
}
}
return 0;
}
No comments:
Post a Comment