National Olympiad in Informatics, China, 2001
The inverse tangent function can be expressed as an infinite series, as shown below:
It is commonly known that the inverse tangent function can be used to
compute . For example, an easy way to compute
is using the method:
Of course, this method is rather inefficient. We can apply the tangent angle sum identity:
After some simple manipulation, the following is obtained:
Using this identity, let and
, then
. Therefore:
Using the inverse tangents of and
to calculate
, the speed is drastically improved.
We take equation (4) and write it in the following form:
where ,
, and
are each positive integers.
The problem is, for a given
, find the value
of
. It is guaranteed that for any
there will always exist
an integer solution. If there are multiple solutions, you are required
to find the minimum value of
.
Input Specification
The input consists of a single positive integer , where
.
Output Specification
The output should contain a single integer, the value of .
Sample Input
1
Sample Output
5
Problem translated to English by .
Comments