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

This is a web related question but is a mathematical problem.

Look at this:




  • A vertical line represents a 1 pixel wide horizontal line.
  • A 'O' represents a space between the lines.
  • All the three rows should have the same width. The space 'O' is streched out to fill the space equally within the row to fill it up. (The last row will get more space than the first.)
  • The space width can't contain decimals.
  • I want to find the perfect width for all three lines between 960 and 1140 pixels wide.


  1. What is the row width?
  2. How did you calculate it?

What I know so far

  • First line have 5 pixels of lines, the second 4 pixels and the third 3 pixels.
  • 960 and 1140 are perfect numbers because they can be divided by 3, 4 and 2, but this case includes borders which makes it tricky.
share|cite|improve this question
up vote 1 down vote accepted

Let the width be $n$. You want $n-5$ to be a multiple of 4, $n-4$ a multiple of 3, and $n-3$ a multiple of 2. This is the same as asking for $n-1$ to be a multiple of 12, so you can take $n$ to be any of the numbers 961, 973, 985, ..., 1129.

share|cite|improve this answer
Good answer. I have checked the numbers and they work. I might even need a row with 5. Is that hard to calculate? In this case it's 960 + 1 + 12, in short. Is there a "magic" number when adding 5 in a row? n - 1 = ? – Jens Törnell Aug 17 '12 at 19:05

Well let the width of the space be n pixels, and $a$, $b$ and $c$ the widths of "O" in the three cases. You need to solve the three equations: $$4a+5=n=4(a+1)+1$$ $$3b+4=n=3(b+1)+1$$ $$2c+3=n=2(c+1)+1$$ So you need $n$ to be 1 more than a multiple of 2,3, and 4 - so $n=12r+1$ will work for any $r$ with $a+1=3r; b+1=4r; c+1=6r$ - which gives you plenty of options to work with.

share|cite|improve this answer
Thanks for the answer. n = 12r + 1 works, I checked. In some cases I might even need 5 in a row. Hard to calculate a formula for that as well? – Jens Törnell Aug 18 '12 at 15:49
Then you should have 60r+1, which will work for 6 too. – Mark Bennet Aug 18 '12 at 16:04
Thanks! That worked! For some reason I can't give you a vote up. Maybe I'm too new in this Q&A. – Jens Törnell Aug 19 '12 at 7:38

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.