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
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)