Application of Poj 4227 inverse tangent function

Source: Internet
Author: User

Description

    反正切函数可展开成无穷级数,有如下公式     (其中0 <= x <= 1) 公式(1)     使用反正切函数计算PI是一种常用的方法。例如,最简单的计算PI的方法:     PI=4arctan(1)=4(1-1/3+1/5-1/7+1/9-1/11+...) 公式(2)     然而,这种方法的效率很低,但我们可以根据角度和的正切函数公式:     tan(a+b)=[tan(a)+tan(b)]/[1-tan(a)*tan(b)] 公式(3)     通过简单的变换得到:     arctan(p)+arctan(q)=arctan[(p+q)/(1-pq)] 公式(4)     利用这个公式,令p=1/2,q=1/3,则(p+q)/(1-pq)=1,有     arctan(1/2)+arctan(1/3)=arctan[(1/2+1/3)/(1-1/2*1/3)]=arctan(1)     使用1/2和1/3的反正切来计算arctan(1),速度就快多了。     我们将公式(4)写成如下形式     arctan(1/a)=arctan(1/b)+arctan(1/c)     其中a,b和c均为正整数。     

Input

    输入文件中只有一个正整数a,其中 1 <= a <= 60000。

Output

    输出文件中只有一个整数,为 b+c 的值。

Sample Input

    1

Sample Output

    5题意:本题在给定1/a=(1/b+1/c)/1-(1/a*(1/b))的情况下,要求最小的a+b,每个样例给定a,如果我们枚举b和c的话,时间消耗不起,我们自然想到把b,c表示为和a相关的等式,顾设b=a+m,c=a+n,带入上式化简得(a*a+1)=m*n,现在只要逆序枚举m或者n就可以了。ac代码如下:
// @zhangxiaoyu///2015/8/13#include <cstdio>#include <cstring>#include <iostream>#include <cmath>#include <algorithm>using namespace STD;typedef Long LongLL;intMain () {LL A;intI while(~scanf("%lld", &a)) { for(i=a;i>=1; i--) {if((a*a+1)%i==0) Break;        } LL ans; ans=i+ (a*a+1)/i+2*a;printf("%lld\n", ans); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Application of Poj 4227 inverse tangent function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.