I took a job interview and the following algorithm was asked and I didn’t manage to find out it’s purpose.
int func(int a, int b)
{
int c = b;
while (c <= a)
c <<= 1;
int d = a;
while (d >= b)
{
c >>= 1;
if (c<= d)
d -= c;
}
return d;
}
CodePudding user response:
This function returns the modulo (a%b).