1734 反正切函数的应用

1734 反正切函数的应用

 

2001年NOI全国竞赛

 时间限制: 3 s
 空间限制: 64000 KB
 题目等级 : 大师 Master
 
 
 
题目描述 Description

都在图里

输入描述 Input Description

输入只有一个正整数a, 1 ≤ a ≤ 60000.

输出描述 Output Description

一个整数,为b + c 的值

样例输入 Sample Input

1

样例输出 Sample Output

5

数据范围及提示 Data Size & Hint
 

分类标签 Tags 点此展开 

 
 
AC代码+题解:
/*
读入正整数a
求满足条件的正整数b,c使得
arctan(1/b)+arctan(1/c)=arctan(1/a)
若有多组解,求出b+c最小的一组解
解题思路:
arctan(1/b)+arctan(1/c)=arctan(1/a)
等价于 tan(arctan(1/b)+arctan(1/c))=tan(arctan(1/a))
等价于 (1/b+1/c)/(1-1/bc)=1/a
等价于 (bc-1)/(b+c)=a
等价于 bc-ab-ac=1
等价于 (b-a)(c-a)=a^2+1
那么显然当b-a和c-a尽量接近时b+c有最小值,所以我们只需要从trunc(sqrt(a*a+1))开始向下枚举a^2+1的因数,找到
第一个就输出
*/
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
#define b(i) i*i
int main(){
    long long i,x;
    cin>>x;
    for(i=floor(sqrt(x*x+1));i;i--) if((x*x+1)%i==0) break;    
    cout<<(2*x+i+(x*x+1)/i);
    return 0;
}
原文地址:https://www.cnblogs.com/shenben/p/5765111.html