您的位置:首页 > 其它

ARCTAN - Use of Function Arctan

2016-06-20 13:37 441 查看
题目地址请点击——

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 B+C.

A,B and C are all positive integers and satisfy the equation below:

arctan(1/A)=arctan(1/B)+arctan(1/C)

Input

The first line contains a integer number T(about 1000).

T lines follow,each contains a single integer A,1≤A≤60000.

Output

T lines,each contains a single integer which denotes to the minimum sum B+C.

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: