HDU 1018 Big number Stirling approximate n!

Source: Internet
Author: User
Tags acos

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.