SPOJ ARCTAN Use of Function Arctan (三角公式atrtan 高中数学)

Use of Function Arctan

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


预备公式:

tan(arctan(A))=A;

arctan(A)+arctan(B)=arctan((A+B)/(1-B*C));


对题目的式子经行变形之后可以发现 A=(B*C-1)/(B+C);

取B=A+m,C=A+n 带入得 m*n=a*a+1;

而我们要求的是 2*A+m+n 的最小值

由不等式 m+n>=2*sqrt(m*n) 知此时m=n时取到最小值

那么对于m来说只需要枚举sqrt(a*a+1)->1 只要整除 a*a+1即是答案

#include<stdio.h>
#include<math.h>
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        long long a,b;
        scanf("%lld",&a);
        b=sqrt(a*a+1);
        while((a*a+1)%b) b--;
        printf("%lld\n",2*a+b+(a*a+1)/b);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值