I have the following computer algorithm that calculates the number of modular subtractions around a modular circle to reach the starting number. To make sure that we don't loop infinitely, assume that startingPoint and subtractBy are both positive even integers and that subtractBy is less than startingPoint.
int countSubtractions(int startingPoint, int subtractBy)
{
int current = startingPoint;
int counter = 0;
while (current != startingPoint)
{
current = current - subtractBy;
if (current < 1)
current = current + startingPoint;
counter = counter +1;
}
return counter;
}
Is there a mathematical way to calculate the result (the number of times I had to subtract modularly to get back to the starting point), without the algorithm?