HDU 1018 -- Big Number

Source: Internet
Author: User

Returns the number of digits of a certain factorial. The most popular method on the Internet is to calculate the logarithm and calculate it hard. The cards are sometimes used, and there are still some clever components. The positive solution may be the method of estimating the factorial in number theory (Source: WIKI): getting the logarithm of this formula can quickly obtain the number of digits. In addition, it is more convenient to make a quick estimation during the competition. [Cpp # include <iostream> # include <cmath> # include <iomanip> using namespace std; const double PI = acos (-1); const double e = exp (1 ); int main () {int testcase; cin> testcase; while (testcase --) {int n; cin> n; double res; if (n = 1 | n = 0) {cout <"1" <endl;} else {res = log10 (sqrt (2 * PI * n )) + n * log10 (n/e); // The string formula cout <setiosflags (ios: fixed) <setprecision (0) <ceil (res) <endl ;}} return 0 ;}

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.