#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 π\pi is a common method. For example, the simplest way to compute π\pi 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 p=12,q=13 p = \frac{1}{2}, q = \frac{1}{3} . Then p+q1pq=1 \frac{p + q}{1 - p q} = 1 , 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 4 4 in the following form:

$$\arctan(\frac{1}{a}) = \arctan(\frac{1}{b}) + \arctan(\frac{1}{c})$$

where a,b,cN+ a, b, c \in \mathbb{N^+} .

Our task is: for each given aa, find the value of b+c b + c . We guarantee that for any a a there is an integer solution. If there are multiple solutions, you must output the one with the smallest b+c b + c .

Input Format

The input file contains only one positive integer a a .

Output Format

The output file contains only one integer, which is the value of b+c b + c .

1
5

Hint

1a6×1041 \le a \le 6\times 10^4

Translated by ChatGPT 5