P5695 [NOI2001] Application of the Arctangent Function

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 = \frac{1}{2}, q = \frac{1}{3} $. Then $ \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) $$

Description

We rewrite formula $ 4 $ in the following form: $$ \arctan(\frac{1}{a}) = \arctan(\frac{1}{b}) + \arctan(\frac{1}{c}) $$ where $ a, b, c \in \mathbb{N^+} $. Our task is: for each given $a$, find the value of $ b + c $. We guarantee that for any $ a $ there is an integer solution. If there are multiple solutions, you must output the one with the smallest $ b + c $.

Input Format

The input file contains only one positive integer $ a $.

Output Format

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

Explanation/Hint

$1 \le a \le 6\times 10^4 $。 Translated by ChatGPT 5