2 条题解

  • 1
    @ 2024-10-29 19:04:20

    牛顿迭代法

    #include<bits/stdc++.h>
    #define int long long
    #define PII pair<int,int>
    #define ULL unsigned long long
    #define all(v) v.begin(), v.end()
    #define debug(a) cout<<#a<<"="<<a<<endl;
    using namespace std;
    constexpr int N =  1 * 1e6 + 10,M = 5 * 1e3 + 10,inf = 0x3f3f3f3f;
    
    double cow_function(double n)
    {
        constexpr static double eps = 1E-15;
        double x =  1;
        while (1)
        {
            double nx = (x + n / x) / 2;
            if(fabs(x-nx) < eps) break;
            x = nx;
        }
        return x;
    }
    void solve()
    {
        double n;
        cin >> n;
        cout << (int)cow_function(n) << '\n';
    }
    signed main()
    {
        ios::sync_with_stdio(0);cin.tie(nullptr),cout.tie(nullptr);
        int _=1;
        // cin>>_;
        while(_--)
        {
            solve();
        }
        return 0;
    }
    
    /**
     *    author: Nijika_jia
     *    created: 2024.10.29 18:42:12
     */
    

    信息

    ID
    38
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    11
    已通过
    6
    上传者