Application of H-arctangent Function
Time limit:1000 ms
Memory limit:10000kb
64bit Io format:% I64d & % i64usubmit status
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. Algorithm split: Derivation. It is very complicated! Code:
#include <stdio.h>#include <string.h>int main(){long long a, m, n, dd;while(scanf("%lld", &a)!=EOF){dd=a*a+1;for(m=a; m>=1; m--){if(dd%m==0){break;}}n=dd/m;printf("%ld\n", 2*a+m+n );}return 0;}
This is an explanation from a compatriot! For reference!