# Find out the position of an element in a loop according to the number of elements

First of all,

I am terrible at math, and this small problem is giving me a nice headache. I'm sure most here will see this as an easy solution. I will try to be as clear as possible.

1. I have X number of items
2. I have 3 positions for these items
3. I need to find out the position of the last item

Example:

X = 5

Item 1 = Position A
Item 2 = Position B
Item 3 = Position C
Item 4 = Position A
Item 5 = Position B


My answer is Item 5 = Position B

I can't figure out the equation! Some help would be much appreciate.

PS: Although is the first time I post at math.stackexchange. I have been a member of other stackexchange website for a while. Let me know if I need to provide more information.

-

Start numbering items at 0 instead of 1. Then the position of the $n$th item is the remainder after dividing $n$ by 3, where 0, 1, and 2 mean positions A, B, and C, respectively.
Here's why: You can always write $n$ in the form $3q + r$, where $q$ and $r$ are the quotient and remainder after dividing $n$ by 3. Since we've started numbering at 0, items divisible by 3 (I.e. 0,3,6,9,...) will always be at position 0 (=position A). So, to find out the position of our item, we just notice that item $3q$ is at position 0, and so ours is at position $r$.