#P5695. [NOI2001] 反正切函数的应用
[NOI2001] 反正切函数的应用
Background
The arctangent function can be expanded into an infinite series, with the following formula:
$$\arctan(x) = \sum_{n = 0}^\infty \frac{(-1) ^ n x ^ {2n + 1}}{2n + 1} ( 0 \le x \le 1 ) \tag{1}$$Using the arctangent function to compute is a common method. For example, the simplest way to compute is:
$$\begin{aligned} \pi & = 4 \arctan(1) \\ & = 4(1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + \dots) \end{aligned} \tag{2}$$However, this method is very inefficient. But we can use the tangent addition formula:
$$\tan(\alpha + \beta) = \frac{\tan(\alpha) + \tan(\beta)}{1 - \tan(\alpha) \tan(\beta)} \tag{3}$$After a simple transformation, we get:
$$\arctan(p) + \arctan(q) = \arctan(\frac{p + q}{1 - p q}) \tag{4}$$Using this formula, let . Then , so we have:
$$\arctan(\frac{1}{2}) + \arctan(\frac{1}{3}) = \arctan(\frac{\frac{1}{2} + \frac{1}{3}}{1 - \frac{1}{2} \cdot \frac{1}{3}}) = \arctan(1)$$Problem Description
We rewrite formula in the following form:
$$\arctan(\frac{1}{a}) = \arctan(\frac{1}{b}) + \arctan(\frac{1}{c})$$where .
Our task is: for each given , find the value of . We guarantee that for any there is an integer solution. If there are multiple solutions, you must output the one with the smallest .
Input Format
The input file contains only one positive integer .
Output Format
The output file contains only one integer, which is the value of .
1
5
Hint
。
Translated by ChatGPT 5