lowest denominator to lie between two rational numbers

191 Views Asked by At

What's the lowest $ m\in \mathbb {N} $ such that the exists an $ n $ with $1/3 >\frac {n}{m}>33/100$? note that there used to be a typo in the inequality which gives the opposite sign

I'm on my phone so I can't really check duplicate, so sorry if it happens to be (I feel it's very likely)

2

There are 2 best solutions below

8
On BEST ANSWER

Let $x$ be the desired quantity. We have $$\cfrac1{3+\cfrac1{33}} < x < \cfrac1{3+\cfrac1\infty}$$ so the continued fraction expansion of $x$ must be $$\cfrac1{3+\cfrac 1{n+y}}$$ where $33<n+y<\infty$. We get the smallest possible denominator by truncating the continued fraction after $n$ (taking $y=0$) and taking $n$ as small as possible, so $n=34$; the answer is $$\cfrac1{3+\cfrac1{34}} = \frac{34}{103} \approx 0.330097.$$

1
On

Since OP has asked for a solution that does not involve the theory of continued fractions, I present this alternative solution which involves no theory whatsoever.

    #include <stdio.h>

    int main(void) {
      unsigned n, d;
      for (d=1; 1; d++) {
        for (n=1; n<d; n++) {
          double q = (double)n/d;
          if (33.0/100 < q && q < 1.0/3) {
            printf("%d / %d = %f\n", n, d, q);
            return 0;
          }
        }
      }
    }

The program exits almost instantly, after producing the output

    34 / 103 = 0.330097