Problem Type : Ad Hoc
#include<stdio.h>
#include<math.h>
unsigned long recurtion(unsigned long n,unsigned long 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,c,n,m,i,d,sum;
scanf("%lu",&n);
for(i=1; i<=n; i++)
{
scanf("%lu %lu %lu",&a,&b,&c);
d=a+b;
sum=recurtion(d,c);
printf("%lu\n",sum);
}
return 0;
}
#include<stdio.h>
#include<math.h>
unsigned long recurtion(unsigned long n,unsigned long 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,c,n,m,i,d,sum;
scanf("%lu",&n);
for(i=1; i<=n; i++)
{
scanf("%lu %lu %lu",&a,&b,&c);
d=a+b;
sum=recurtion(d,c);
printf("%lu\n",sum);
}
return 0;
}
No comments:
Post a Comment