3 条题解

  • 7
    #include <iostream>
    #include <cmath>
    using namespace std;
    int GetLength(double x);
    int main()
    {
    int n; cin>>n;
    double y=1;
    for(int x=2; x<=n; x++)
    y=y*x;
    cout<<GetLength(y)<<endl;
    return 0;
    }
    int GetLength(double x)
    {
    int n=0;
    while(x>=1) // !!!!
    n++, x/=10;
    return n;
    }
    int GetLength(int x)
    {
    int n; cin>>n;
    double len=0;
    for(int i=1; i<=n; i++)
    len += log(i)/log(10);
    cout << (int)len + 1;
    return 0;
    }
    
    
    • @ 2025-10-02 14:41:13

      时间复杂度可以优化,n=200就超时了

  • 0
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        long long ans=1;
        double k=1; 
        cin>>n;
        while(n)
            if(k<10)
            {
                k*=n;
                n--;
            }
            else
            {
                ans++;
                k/=10;
            }
        cout<<ans;
        return 0;
    }//时间复杂度 O(n) 
    
  • -5

    #include <iostream>
    #include <cmath>
    using namespace std;
    int GetLength(double x);
    int main()
    {
    int n; cin>>n;
    double y=1;
    for(int x=2; x<=n; x++)
    y=y*x;
    cout<<GetLength(y)<<endl;
    return 0;
    }
    int GetLength(double x)
    {
    int n=0;
    while(x>=1) // !!!!
    n++, x/=10;
    return n;
    }
    int GetLength(int x)
    {
    int n; cin>>n;
    double len=0;
    for(int i=1; i<=n; i++)
    len += log(i)/log(10);
    cout << (int)len + 1;
    return 0;
    }

  • 1

信息

ID
1035
难度
6
分类
(无)
标签
递交数
298
已通过
70
通过率
23%
上传者