3 条题解

  • 1
    @ 2024-7-25 12:47:08

    参考答案:

    #include<iostream>
    #include<cmath>
    
    using namespace std;
    
    int main()
    {
        int a;
    
        cin >> a;
        cout << (int)sqrt(a);
    
        return 0;
    }
    
    • 0
      @ 2025-10-14 16:43:21

      Python:

      import math
      
      a = int(input())
      print("%d" % math.sqrt( a))
      
      • 0
        @ 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
         */
        
        • 1

        信息

        ID
        38
        时间
        1000ms
        内存
        256MiB
        难度
        5
        标签
        递交数
        21
        已通过
        13
        上传者