The formula given by R. Burton in a comment is very useful for analyzing this problem. We have the following iteration function, where $\lfloor x \rfloor$ is the floor function:
$$
f(x) = \lfloor x \rfloor(x-\lfloor x \rfloor)
$$
We get a sequence by repeatedly applying this function until $a_n$ is an integer or $0 < a_n < 1$.
$$
\begin{array}{rcl}
a_0 &=&\frac{p}{q} \\
a_{n+1} &=& f(a_n)
\end{array}
$$
Note that we can just as well take a value for $a_0$ that is not a rational number but an arbitrary positive real number. I think this generalization makes the problem easier, because we can forget about numerators and denominators.

This is the plot of $f$:

You can see that, for example, if $4 < x < 5$, then $0 < f(x) < 4$.

If we call the area between two adjacent integers on the x-axis a column, then we can say that with every application of $f$, the value of $a_n$ moves at least one column to the left. Or, in a formula, $\lfloor a_{n+1} \rfloor < \lfloor a_n \rfloor$.

But of course $a_n$ is never negative, so this process must terminate.

# Problem 2

Let $f^*$ be the function $f$ repeated until the result is an integer or between 0 and 1. Where $f^*$ is continuous, its graph looks like this, lines from 0 to 1 directly next to each other:

The vertical gray lines indicate where $f^*$ is discontinuous and has a positive integer value. (value is not visible in the plot.) The positions of the vertical lines can be calculated with the following recurrence relation. The set $L_i$ contains all discontinuities of $f^*$ up to $i$ and has $2^{i-1}$ elements.
$$
\begin{array}{rcl}
L_1 &=& \{1\} \\
L_{i+1} &=& L_i\ \cup\ \{i + \frac{k}{i}\ |\ k \in L_i\}
\end{array}
$$
For drawing the plot I used $L_7$, which is equal to
$$
\left\{1,2,\frac{5}{2},3,\frac{10}{3},\frac{11}{3},\frac{23}{6},4,\frac{17}{4},\frac{9}{2},\frac{37}{8},\frac{19}{4},\frac{29}{6},\frac{59}{12},\frac{119}{24},5,\frac{26}{5},\frac{27}{5},\frac{11}{2},\frac{28}{5},\frac{17}{3},\frac{86}{15},\frac{173}{30},\frac{29}{5},\frac{117}{20},\frac{59}{10},\frac{237}{40},\frac{119}{20},\frac{179}{30},\frac{359}{60},\frac{719}{120},6,\frac{37}{6},\frac{19}{3},\frac{77}{12},\frac{13}{2},\frac{59}{9},\frac{119}{18},\frac{239}{36},\frac{20}{3},\frac{161}{24},\frac{27}{4},\frac{325}{48},\frac{163}{24},\frac{245}{36},\frac{491}{72},\frac{983}{144},\frac{41}{6},\frac{103}{15},\frac{69}{10},\frac{83}{12},\frac{104}{15},\frac{125}{18},\frac{313}{45},\frac{1253}{180},\frac{209}{30},\frac{279}{40},\frac{419}{60},\frac{559}{80},\frac{839}{120},\frac{1259}{180},\frac{2519}{360},\frac{5039}{720},7\right\}.
$$

The corresponding Mathematica code is: (Wolfram Alpha)

```
Fold[Join[#1, #2 + #1/#2] &, {1}, Range[6]]
```

Let $x = \frac{p}{q}$ be a positive number, then we have
$$
f^* \left( \frac{p}{q} \right) = \frac{p \mod q}{q}\quad \iff \quad
f^*(x) = x - \lfloor x \rfloor.
$$
If we draw $x - \lfloor x \rfloor$ on top of $f^*(x)$, we get this image:

The equation $f^*(x) = x - \lfloor x \rfloor$ is true where the blue and orange lines overlap or cross, except at positive integers, where it is false because the right hand side is $0$.

We can see that the equation holds for $0 \le x < 1$ and $1 < x < 2$. It is also true at one point on every blue line that does not start or end at an integer. So for every integer $n \ge 2$, there are $|L_{n+1}| - |L_n| - 2 = 2^{n-1}-2$ points between $n$ and $n+1$ for which the equation is true.

To get the coordinates of the points, we have to equate a blue line with an orange line. Let $a$ and $b$ be the values of two adjacent non-integer discontinuity points, for example $a = \frac{10}{3}$ and $b = \frac{11}{3}$ to get the first point. Then the equations for the blue and orange lines are:
$$
\begin{array}{rcl}
l_b(x) &=& \frac{x - a}{b - a} \\
l_o(x) &=& x - \lfloor a \rfloor
\end{array}
$$
Solving $l_b(x) = l_o(x)$ gives us:
$$
x = \frac{a + \lfloor a \rfloor(a - b)}{1 + a - b}
$$
In Mathematica we can use this code to output all numbers between 2 and 7 for which the equation holds:

```
x[a_, b_] := (a + Floor[a](a - b)) / (1 + a - b);
list = Fold[Join[#1, #2 + #1/#2] &, {1}, Range[6]];
intervals = Select[Partition[list, 2, 1], NoneTrue[#, IntegerQ] &];
points = x @@ # & /@ intervals
```

This gives us
$$
\left\{\frac{7}{2},\frac{19}{5},\frac{13}{3},\frac{32}{7},\frac{33}{7},\frac{53}{11},\frac{54}{11},\frac{114}{23},\frac{21}{4},\frac{49}{9},\frac{50}{9},\frac{79}{14},\frac{40}{7},\frac{167}{29},\frac{168}{29},\frac{111}{19},\frac{112}{19},\frac{77}{13},\frac{232}{39},\frac{352}{59},\frac{353}{59},\frac{713}{119},\frac{31}{5},\frac{70}{11},\frac{71}{11},\frac{111}{17},\frac{112}{17},\frac{232}{35},\frac{233}{35},\frac{154}{23},\frac{155}{23},\frac{318}{47},\frac{319}{47},\frac{483}{71},\frac{484}{71},\frac{976}{143},\frac{977}{143},\frac{199}{29},\frac{200}{29},\frac{408}{59},\frac{409}{59},\frac{618}{89},\frac{619}{89},\frac{1246}{179},\frac{1247}{179},\frac{830}{119},\frac{831}{119},\frac{1670}{239},\frac{1671}{239},\frac{2511}{359},\frac{2512}{359},\frac{5032}{719}\right\}.
$$