ARCTAN - Use of Function Arctan

45 篇文章 0 订阅
2 篇文章 0 订阅

题目地址请点击——


ARCTAN


Description

相信大家都看得懂英文吧,我就不翻译了吧…………

It is easy to know that

arctan(1/2)+arctan(1/3)=arctan(1)

Given number A , 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 (about 1000).
T lines follow,each contains a single integer A 1A60000 .


Output

T lines,each contains a single integer which denotes to the minimum sum B+C.


Sample Input

1


Sample Output

5


Solution

解法一:附上扫雷神犇Cai的坑爹解法
解法二:

tan(α+β)=1A,tanβ=1B,tanα=1C

A=BC1B+C

B+C=k ,则
BC=Ak+1

BC 为一元二次方程
x2kx+Ak+1=0
的两个根。
那么
k24Ak4
为完全平方数。
k24Ak4=s2
k=4A+16A2+16+4s22=2A+4A2+s2+4

4A2+s2+4 为完全平方数。
4A2+s2+4=r2 ,则 4A2+4=(r+s)(rs)
枚举 4A2+4 的约数即可。


Code

因为有代码长度限制,所以读者在复制代码的时候请注意删除缩进以及空格…………

#include<iostream>
#include<cmath>

typedef unsigned long long L;
using namespace std;

L t,i,T,a,b,k;

main(){
    cin>>t;
    while(t--){
        cin>>a;
        T=a*a*4+4;
        b=sqrt(T);
        i=b+1;
        while(--i)
            if(!(T%i)&&!((i+T/i)&1)){
                k=(T/i-i)/2;
                break;
            }
        cout<<2*a+L(sqrt(T+k*k)+0.5)<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Here's a possible implementation of a rapid 16-bit arctan function using a lookup table and linear interpolation: ```c #include <stdint.h> // Constants for the lookup table #define SIZE 1024 #define PI_OVER_2 16384 // 2^14 * PI/2 #define ATAN_1_OVER_X_MAX 8192 // 2^13 // Lookup table for arctan(1/x) uint16_t atan_1_over_x[SIZE + 1]; // Initialize the lookup table void init_atan_1_over_x() { for (int i = 0; i <= SIZE; i++) { double x = (double)i / SIZE; atan_1_over_x[i] = (uint16_t)(atan(1 / x) * PI_OVER_2 / M_PI); } } // Rapid 16-bit arctan function using lookup table and linear interpolation uint16_t atan16(int16_t x) { if (x == 0) return 0; int16_t abs_x = abs(x); uint16_t index = abs_x >= SIZE ? SIZE : abs_x; uint16_t y0 = atan_1_over_x[index]; uint16_t y1 = atan_1_over_x[index + 1]; uint16_t dy = y1 - y0; uint16_t frac = ((uint32_t)(abs_x - index) << 16) / SIZE; uint16_t y = y0 + frac * dy; return x > 0 ? PI_OVER_2 - y : y - PI_OVER_2; } ``` The `init_atan_1_over_x()` function initializes a lookup table for arctan(1/x) values. The function `atan16(x)` takes a 16-bit integer `x` and returns the 16-bit arctan value in radians (scaled by 2^14). The function first looks up the arctan(1/x) value in the table using the absolute value of `x`, linearly interpolates between the two closest table values to get the arctan value for `x`, and then adjusts the sign of the result based on the sign of `x`. Note that this implementation is not optimized for speed and may not be suitable for real-time applications.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值