ARCTAN - Use of Function Arctan

来源:互联网 发布:移动互联网数据 编辑:程序博客网 时间:2024/04/28 13:46

题目地址请点击——


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.
AB 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 A1A60000.


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=BC1B+C

B+C=k,则
BC=Ak+1

BC 为一元二次方程
x2kx+Ak+1=0
的两个根。
那么
k24Ak4
为完全平方数。
k24Ak4=s2
k=4A+16A2+16+4s22=2A+4A2+s2+4

4A2+s2+4 为完全平方数。
4A2+s2+4=r2,则 4A2+4=(r+s)(rs)
枚举 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;}
1 0
原创粉丝点击