Take the first few digits of a large number.

Source: Internet
Author: User

This idea can be understood through 2.2.1:

First, let's look at the nature of the logarithm. Loga (B ^ c) = C * Loga (B), Loga (B * C) = Loga (B) + Loga (C );
Assume that a number of 10234432 is given, then log10 (10234432) = log10 (1.0234432*10 ^ 7) = log10 (1.0234432) + 7;

Log10 (1.0234432) is the fractional part of log10 (10234432.

Log 10 (1.0234432) = 0.010063744
10 ^ 0.010063744 = 1.023443198
So it is obvious that we need to take a few digits ~
First take the logarithm (for 10), and then get the fractional part of the result bit, POW (10.0, bit), if the answer is still <1000, then always multiply by 10.
Note that 0 ~ is processed first ~ 20 items to facilitate processing ~

This question uses the formula of the series: An = (1/√ 5) * [(1 + √ 5)/2) ^ N-(1-√ 5) /2) ^ N] (n = 1, 2, 3 .....)

 


Obtain the logarithm

 


Log10 (an) =-0.5 * log10 (5.0) + (double) n) * log (f)/log (10.0) + log10 (1-(1-√ 5)/(1 + √ 5) ^ N)

Where f = (SQRT (5.0) + 1.0)/2.0;
Because log10 (1-(1-√ 5)/(1 + √ 5) ^ N) approaches 0
Therefore, you can write log10 (an) =-0.5 * log10 (5.0) + (double) n) * log (f)/log (10.0 );
Finally, the fractional part is taken.

 

Take the first few digits of a large number.

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.