Description
It's easy to know that arctan(1/2)+arctan(1/3)=arctan(1).The problem is,to some fixed number A,you have to 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.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 1
Sample Output
5
Hint
Some new test data has been added on Feb.15, 2009, 36 users lose their Accepted.
Source limit: 256B
Languages : All except: C99 strict ERL JS
#include<stdio.h>
#include<math.h>
int main(){
long long t,a,i;
scanf("%lld",&t);
while(t--){
scanf("%lld",&a);
long long i=(long long)sqrt(1.0*(a*a+1));
while((a*a+1)%i) i--;
printf("%lld\n",2*a+i+(a*a+1)/i);
}
return 0;
}