NOI '01 P4 - Applications of Arctangent

View as PDF

Submit solution

Points: 15
Time limit: 0.18s
Memory limit: 64M

Problem type
National Olympiad in Informatics, China, 2001

The inverse tangent function can be expressed as an infinite series, as shown below:

(1)arctan(x)=n=0(1)nx2n+12n+1(0x1)

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:

(2)π=4arctan(1)=4(113+1517+19111+)

Of course, this method is rather inefficient. We can apply the tangent angle sum identity:

(3)tan(α+β)=tan(α)+tan(β)1tan(α)tan(β)

After some simple manipulation, the following is obtained:

(4)arctan(p)+arctan(q)=arctan(p+q1pq)

Using this identity, let p=12 and q=13, then p+q1pq=1. Therefore:

arctan(12)+arctan(13)=arctan(12+1311213)=arctan(1)

Using the inverse tangents of 12 and 13 to calculate arctan(1), the speed is drastically improved.

We take equation (4) and write it in the following form:

arctan(1a)=arctan(1b)+arctan(1c)

where a, b, and c are each positive integers.

The problem is, for a given a (1a60000), find the value of b+c. It is guaranteed that for any a there will always exist an integer solution. If there are multiple solutions, you are required to find the minimum value of b+c.

Input Specification

The input consists of a single positive integer a, where 1a60000.

Output Specification

The output should contain a single integer, the value of b+c.

Sample Input

Copy
1

Sample Output

Copy
5

Problem translated to English by Alex.


Comments

There are no comments at the moment.