Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I need to know how the equation below works.

So I have a number line 0 to 21 each cell is divided into 3 units so 0-2 belongs to first unit, 3-5 belongs to the second unit and so on. This 3 unit cell is further divided into 2 unit cells. So what you want to determine is given a number within this line, which 2 unit block this number belongs to.

Example, if you have 10 10/3=3.333.... and so we know that 10 belongs to the 3rd block and now we need to determine where in this 3rd block 10 belongs to (remember the cell is further divided into 2 units) so the correct equation is ((int)(10/3)*2)/2 = 3 so we know that 10 belongs to the 3rd block first section. If you have 11, ((int)(11/3)*2)/2 = 3.5 so we know that this number belongs to the second block of the block 3. Could someone please explain why does ((int)(11/3)*2)/2 this equation works?


share|cite|improve this question
Note that (int) removes all the decimal point. You're converting a number to Java int type. – Mayumi Jun 3 '11 at 3:19
up vote 1 down vote accepted

Suppose $N = 3a+b$, where $0 \leq b \leq 2$. So $N$ belongs to the $a$th cell. Your equation amounts to $$ \frac{1}{2} \lfloor \textstyle \frac{2}{3} N \rfloor = \displaystyle \frac{1}{2} \lfloor 2a + \textstyle \frac{2}{3} b \rfloor = \displaystyle \frac{1}{2} \begin{cases} 2a & b \leq 1, \\ 2a+1 & b = 2 \end{cases} = \begin{cases} a & b \leq 1, \\ a + 1/2 & b = 2. \end{cases} $$ Here $\lfloor x \rfloor$ is the floor of $x$, which is the largest integer $m$ such that $m \leq x$ (this is equivalent to your int).

If $b \leq 1$ then $(2/3)b < 1$ and so $\lfloor 2a + (2/3)b \rfloor = 2a$. If $b = 2$ then $(2/3)b = 4/3 > 1$ and so $\lfloor 2a + (2/3)b \rfloor = 2a + 1$.

share|cite|improve this answer
Thanks for the reply! – Mayumi Jun 3 '11 at 5:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.