Topic Link: Click to open the link
Sterling Number: Click to open link
Test instructions is calculated n! The number of digits
That is, ans = log10 (n!) = log10 (sqrt (2πn)) + N*LOG10 (n/e)
#include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include < stdlib.h> #include <string.h> #include <limits.h> #include <vector> #include <string># Include <time.h> #include <math.h> #include <iomanip> #include <queue> #include <stack># Include <set> #include <map>const int inf = 1e8;const double eps = 1e-8;const double pi = ACOs ( -1.0); Template & Lt;class t> inline BOOL Rd (T &ret) {char c; int sgn; if (C=getchar (), c==eof) return 0; while (c!= '-' && (c< ' 0 ' | | C> ' 9 ')) C=getchar (); sgn= (c== '-')? -1:1; ret= (c== '-')? 0: (c ' 0 '); while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 '); RET*=SGN; return 1; } template <class t> inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X;} if (x>9) pt (X/10); Putchar (x%10+ ' 0 '); }using namespace Std;typedef Long long ll;typedef pair<int,int> Pii;conSt Double Pi = ACOs ( -1.); Const double E = 2.718281828459045;double n; int main () {int T; rd (T); while (t--) {cin>>n;if (n = = 1) {puts ("1"); continue;} Double ans = log10 (sqrt (2.*pi*n)); ans + = n * log10 (n/e); cout<<fixed<<setprecision (0) <<ceil (ans) < <endl;} return 0;}
HDU 1018 Big number Stirling approximate n!