214k views
5 votes
I need to know a formula, that if I plug a number in to a variable (let's say N) it will give me that digit of pi. For example, plugging in 5 would give me the fifth digit of pi, 9.

1 Answer

2 votes

There is no closed-form algebraic formula to compute the n-th digit of pi for an arbitrary n. However, there are various algorithms that can be used to compute pi to a desired number of digits, and it is possible to extract individual digits from the resulting decimal representation.

One such algorithm is the Bailey-Borwein-Plouffe (BBP) formula, which can be used to compute the n-th hexadecimal (base-16) digit of pi without needing to compute any of the preceding digits. The formula is:

pi = SUM[k=0 to infinity] 16^-k {4/(8k+1) - 2/(8k+4) - 1/(8k+5) - 1/(8k+6)}

Using this formula, the n-th hexadecimal digit of pi can be computed using the following expression:

floor(16^(n-1) * {4/(8n+1) - 2/(8n+4) - 1/(8n+5) - 1/(8n+6)})

Note that this formula only gives the n-th hexadecimal digit of pi, not the n-th decimal digit. To convert a hexadecimal digit to a decimal digit, you can multiply it by 0.0625 (i.e., 1/16), which is the value of one hexadecimal place.

User Jongsu Liam Kim
by
7.9k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories