SPOJ1440 Use of Function Arctan

终于见到什么是真正的数学题了!我的数学竞赛之魂又燃了起来!


原等式为:

arctan(1/A) = arctan(1/B)+arctan(1/C)


设arctan(1/B)=b,arctan(1/C)=c,对等式两边同时取tan并化简:

1/A = tan(b+c)

1/A = (tanb+tanc)/(1-tanb*tanc)

1/A = (1/B+1/C)/(1-1/BC)

1/A = (B+C)/(BC-1)

A = (BC-1)/(B+C)


设B=A+x,C=A+y,带入上式:

2A^2+Ax+Ay = A^2+Ax+Ay+xy-1

A^2 = xy-1

y = (A*A+1)/x


从中间开始枚举答案即可


这还不算完,最坑爹的是,source limit: 256B

B尼玛啊!!!从没见过这么奇葩的有木有!!!贡献了4次CLE有木有!!!

简化了又简化,271B= =,再把所有空格删掉,216B,AC!

#include <cstdio>
#include <cmath>
typedef long long ll;
int main()
{
    ll T,a,x;
    scanf("%lld",&T);
    while (T--)
    {
        scanf("%lld",&a);
        x=sqrt(a*a+1.0);
        while ((a*a+1)%x) x--;
        printf("%lld\n",a+a+x+(a*a+1)/x);
    }
	return 0;
}


你可能感兴趣的:(SPOJ1440 Use of Function Arctan)