0

The value of pi = 3.1415926535... can approximate pi with rational numbers like this:

  • 22/7 = 3.142857142857...
  • 355/113 = 3.141592920353...

I want to construct more accurate fractions, so:
Please tell me the fast algorithm of finding integers p, q (1 <= q <= n) such p/q is nearest to pi.

I only have a brute-force algorithm and it takes O(n) to find it, so it is slow for n <= 10^12.

Do you have any efficient algorithm?

EDIT:
Different from this question because I already know the value of pi and I only want to construct the most accurate fraction that denominator is less or equal to n.

Community
  • 1
  • 1
square1001
  • 1,402
  • 11
  • 26

0 Answers0