Application of poj 1183 arc tangent function (push formula)

Source: Internet
Author: User

Arc tangent function application
Time limit:1000 ms   Memory limit:10000 K
Total submissions:14468   Accepted:5227

Description

The arc tangent function can be expanded into an infinite series, with the following formula

(0 <= x <= 1) formula (1)

Using the arc tangent function to calculate pi is a common method. For example, the simplest method to calculate pi is as follows:

Pi = 4 arctan (1) = 4 (1-1/3 + 1/5-1/7 + 1/9-1/11 +...) formula (2)

However, the efficiency of this method is very low, but we can use the tangent function formula based on the angle:

Tan (a + B) = [tan (A) + Tan (B)]/[1-Tan (a) * Tan (B)] formula (3)

The following is a simple transformation result:

Arctan (p) + arctan (q) = arctan [(p + q)/(1-pq)] formula (4)

Using this formula, if p = 1/2, q = 1/3, (p + q)/(1-pq) = 1

Arctan (1/2) + arctan (1/3) = arctan [(1/2 + 1/3)/(1-1/2*1/3)] = arctan (1)

Arctan (1) is calculated using the arc tangent of 1/2 and 1/3, and the speed is much faster.
The formula (4) is written as follows:

Arctan (1/a) = arctan (1/B) + arctan (1/C)

Both A, B, and C are positive integers.

Our problem is: For each given a (1 <= A <= 60000), evaluate the value of B + C. We ensure that there is an integer solution for any. If there are multiple solutions, you must provide the minimum solution of B + C.

Input

The input file only has a positive integer a, where 1 <=a <= 60000.

Output

The output file contains only one integer, which is the value of B + C.

Sample Input

 
1

Sample output

 
5

Source

Noi 01 question about a formula, pay attention to the data range

1/A = (1/B + 1/C)/(1-1/(B * C) => bc-1 = A (B + C) assume B = a + M and C = a + N (B and C is always bigger than a) (a + M) (a + n) -1 = a (a + M + A + n) => A * A + A * n + A * m + M * n-1 = 2 * a * A + M * A + N * A => M * n = A * + 1

Enumerate M (or N ).

The key is B = a + M, c = a + N. Here is a conversion.

 1 # Include <cstdio> 2 # Include <cmath>3 # Include <cstring> 4 # Include <stdlib. h> 5 # Include <algorithm> 6   # Define Ll _ int64 7   Using   Namespace  STD;  8   Int  Main ()  9   {  10      //  Freopen ("in.txt", "r", stdin );  11   Ll;  12 Scanf ( "  % I64d  " ,& A );  13       For (Ll I = A; I> = 0 ; I --) //  Enumerative m  14   { 15           If (A * A + 1 ) % I = 0 ) //  N = (A * A + 1)/I m = I  16   {  17 Printf ( "  % I64d \ n  " , A + I + A + (A * A + 1 )/ I );  18              Break  ;  19   }  20   }  21       Return   0  ;  22 }
View code

 

Application of poj 1183 arc tangent function (push formula)

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.