Link: https://www.nowcoder.com/acm/contest/75/A
Source: Niuke.com
Topic description
One day, the husband was interested in how many digits a number has, but he didn't want to be like the common man,
so he wanted to know if he was given an integer n, ask for n! The number of digits in octal is how many digits.
so he wanted to know if he was given an integer n, ask for n! The number of digits in octal is how many digits.
Enter description:
The first line is an integer t (0<t<=1000000) (representing t group data) Next t lines, each line has an integer n (0<=n<=10000000)
Output description:
output n! The number of digits in base 8.
enter
3 4 2 5
output
2 1 3
The application of Stirling formula (see my reprint of Stirling formula if you don't understand)
Stirling formula
It is actually ceil(x) or written as unsigned long long(x+1)
x<2, you have to judge by yourself, because of the accuracy problem
cin closes the synchronization also TLE, speechless
#include <iostream> #include <cstdio> #include <cmath> const double pi=acos(-1); typedef unsigned long long ull; using namespace std; int main() { int t; scanf("%d",&t); //ios::sync_with_stdio(false); //cin>>t; while (t--) { ull n,x=1; scanf("%llu",&n); //cin>>n; if(n>1) x=ull(log(sqrt(2*pi*n))/log(8)+n*log(n/exp(1))/log(8)+1); printf("%llu\n",x); } return 0; }