ZCMU-1129 accidentally fell in love with you (formula water problem)

topic

1129: Chapter Five: Falling in Love with You Accidentally

Time Limit: 5 Sec Memory Limit: 128 MB
Submit: 661 Solved: 176
[Submit][Status][Web Board]
Description

Most people with O blood are activists, and Zheng Wei has taken this characteristic to the extreme. In class the next day, Ruan Ruan was surprised to find that she was struggling to write in class like never before, so he leaned in and asked, "What are you writing?" Zheng Wei showed Ruan Ruan what she had done in the morning. With the crystallization of wisdom, Ruan Ruan looked at it, "Captive Chen Xiaozheng's detailed action plan..." She was speechless after she finished reading. It's a pretty new small book. Nearly ten pages have been written eloquently on it. The small prints are neat and tidy, and all links and steps are all clear. The key points and precautions are even underlined.

Action strategy first: Encounter Chen Xiaozheng in the self-study classroom, Zheng Wei sat behind him, pretending not to know, and asked him a mathematical question: Do you know how many factorials are in the 520? However, Chen Xiaozheng ignored Zheng Wei at all. .

Do you know the answer to this question? Hurry up and think about it, if someone comes to ask you someday. . . . . .

Input

One N per line, 0<=N<10^7, you need to answer quickly!

Output

Output the number of digits of the factorial of N.

Sample Input

5
6
520

Sample Output

3
3
1189

idea

At first glance, this question may feel that violence must be exploded. A search on the Internet turns out to have a formula...
Insert picture description here

Insert picture description here

Then just set the formula directly...

int str(int n)
{
    
    
     return floor(log10(sqrt(2*PI*n))+n*log10(n/e))+1;
}

AC code

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define pre(i,a,b) for(int i=a;i>=b;--i)
#define m(x) memset(x,0,sizeof x)
const double PI = acos(-1);
const double e = exp(double(1));
const int maxn = 1e6+5;
int str(int n)
{
    
    
    return floor(log10(sqrt(2*PI*n))+n*log10(n/e))+1;
}
int main()
{
    
    
    
    int n;
    while(~scanf("%d",&n))
    {
    
    
        if(n<=3)printf("1\n");
        else
        printf("%d\n",str(n));
    }
    return 0;
}


Guess you like

Origin blog.csdn.net/DAVID3A/article/details/115185233