反正切函数的应用
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 15514 | Accepted: 5548 |
Description
反正切函数可展开成无穷级数,有如下公式
(其中0 <= x <= 1) 公式(1)
使用反正切函数计算PI是一种常用的方法。例如,最简单的计算PI的方法:
PI=4arctan(1)=4(1-1/3+1/5-1/7+1/9-1/11+…) 公式(2)
然而,这种方法的效率很低,但我们可以根据角度和的正切函数公式:
tan(a+b)=[tan(a)+tan(b)]/[1-tan(a)*tan(b)] 公式(3)
通过简单的变换得到:
arctan(p)+arctan(q)=arctan[(p+q)/(1-pq)] 公式(4)
利用这个公式,令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)
使用1/2和1/3的反正切来计算arctan(1),速度就快多了。
我们将公式(4)写成如下形式
arctan(1/a)=arctan(1/b)+arctan(1/c)
其中a,b和c均为正整数。
我们的问题是:对于每一个给定的a(1 <= a <= 60000),求b+c的值。我们保证对于任意的a都存在整数解。如果有多个解,要求你给出b+c最小的解。

使用反正切函数计算PI是一种常用的方法。例如,最简单的计算PI的方法:
PI=4arctan(1)=4(1-1/3+1/5-1/7+1/9-1/11+…) 公式(2)
然而,这种方法的效率很低,但我们可以根据角度和的正切函数公式:
tan(a+b)=[tan(a)+tan(b)]/[1-tan(a)*tan(b)] 公式(3)
通过简单的变换得到:
arctan(p)+arctan(q)=arctan[(p+q)/(1-pq)] 公式(4)
利用这个公式,令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)
使用1/2和1/3的反正切来计算arctan(1),速度就快多了。
我们将公式(4)写成如下形式
arctan(1/a)=arctan(1/b)+arctan(1/c)
其中a,b和c均为正整数。
我们的问题是:对于每一个给定的a(1 <= a <= 60000),求b+c的值。我们保证对于任意的a都存在整数解。如果有多个解,要求你给出b+c最小的解。
Input
输入文件中只有一个正整数a,其中 1 <= a <= 60000。
Output
输出文件中只有一个整数,为 b+c 的值。
Sample Input
1
Sample Output
5
试题分析:
首先我们根据 公式(4) arctan(p)+arctan(q)=arctan[(p+q)/(1-pq)] 可知,其[(p+q)/(1-pq)] 等于a,所以我们要求的b+c就可以根据
a=[(bc – 1)/ (b + c)]解得。
解:
令 x = b + c
则 c = x – b
∴bc – 1 = ax
∴bx-b² – 1 = ax
(b-a)x = b²+1
∴x = (b²+1)/ (b-a)
再令 y = b-a
则 x = [(y+a)²+1]/y
ƒ(y) = y + (a²+1)/y + 2*a
对于这个对号函数,当 y<√(a²+1),该函数为减函数,所以只需要从a到1依次试下去,第一次到a²+1的约数时的y所对应的ƒ(y)就是问题的解答
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
ll ans;
ll a;
for(a = n;a >= 1;a --)
{
if((n*n+1)%a == 0)
break;
}
ans = (n*n+1)/a + 2*n + a;
cout<<ans<<endl;
return 0;
}