You have the following game:
You start with a set $S$ with a number $n$ of positive integer elements, $n \ge 2$. At each step, you add to the set any new number $i$, as long as $i = |a-b|$ and $a$ and $b$ already belong to the set, $a \neq b$. Repeat this until no more new numbers can be added to the set.
Now, given a initial set $S$, how can you calculate the number of members of the set after the game is over? (Assume you will add all possible elements).
Some background on the question:
I know this sounds like homework, but it's not. The question appeared after solving a problem in codeforces, a programming competition website - http://codeforces.com/problemset/problem/346/A (The contest in which this problem appeared is over and now you are allowed to discuss it :)
I managed to solve the problem and get my solution accepted on the website, therefore I already know the formula that answers this question. The problem is: it was just a guess. Although I've tried a lot to devise some reasoning that would lead me to the answer, I could not. So I am more interested in how do you arrive to the solution, rather than the solution itself.
(Also, I thought about asking "how do you prove that the final number of elements is equal the formula", but the reasoning required to achieve this would be different, although I couldn't prove it too :( )