ARCTAN
Description
相信大家都看得懂英文吧,我就不翻译了吧…………
It is easy to know that
arctan(1/2)+arctan(1/3)=arctan(1)
Given number A , write a program to calculate the minimum sum
A ,
Input
The first line contains a integer number
T
(about
T
lines follow,each contains a single integer
Output
T
lines,each contains a single integer which denotes to the minimum sum
Sample Input
1
Sample Output
5
Solution
解法一:附上扫雷神犇Cai的坑爹解法。
解法二:
由
tan(α+β)=1A,tanβ=1B,tanα=1C
得
A=BC−1B+C
设 B+C=k ,则
BC=Ak+1
, 则 B、C 为一元二次方程
x2−kx+Ak+1=0
的两个根。 那么
k2−4Ak−4
为完全平方数。 设 k2−4Ak−4=s2 ,
k=4A+16A2+16+4s2−−−−−−−−−−−−−√2=2A+4A2+s2+4−−−−−−−−−−−√
则 4A2+s2+4−−−−−−−−−−−√ 为完全平方数。
设 4A2+s2+4=r2 ,则 4A2+4=(r+s)(r−s)
枚举 4A2+4 的约数即可。
Code
因为有代码长度限制,所以读者在复制代码的时候请注意删除缩进以及空格…………
#include<iostream>
#include<cmath>
typedef unsigned long long L;
using namespace std;
L t,i,T,a,b,k;
main(){
cin>>t;
while(t--){
cin>>a;
T=a*a*4+4;
b=sqrt(T);
i=b+1;
while(--i)
if(!(T%i)&&!((i+T/i)&1)){
k=(T/i-i)/2;
break;
}
cout<<2*a+L(sqrt(T+k*k)+0.5)<<endl;
}
return 0;
}