【Daily Blue Bridge】13, 13th and three years provincial Java group real question "Golden consecutive points"

Hello, I am the little gray ape, a programmer who can write bugs!

Welcome everyone to pay attention to my column " Daily Blue Bridge ". The main function of this column is to share with you the real questions of the Blue Bridge Cup provincial competitions and finals in recent years, analyze the algorithm ideas, data structures and other content that exist in it, and help you learn To more knowledge and technology!

Title: Golden consecutive points

The golden continuous number 0.61803... is an irrational number. This constant is very important and will appear in many engineering problems. Sometimes it is necessary to find this number very accurately.

For some precision engineering, the accuracy of the constant is very important. Maybe you have heard of the Hubble Space Telescope. After it first launched into the sky, it found an artificial processing error. For such a behemoth, it is actually a mirror processing that is more than a hair. It's just a mistake that is many times thinner, but it makes it a "myopia"

Closer to home, how do we find the value of the golden ratio as accurate as possible? There are many ways

The simpler one is to use continued fractions

The more "expansion number" calculated for this continued fraction, the closer its value is to the golden section number

Please use this feature to find a sufficiently accurate value of the golden ratio, requiring rounding to 100 digits after the decimal point

The value with 3 digits after the decimal point: 0.618

The value with 4 digits after the decimal point: 0.6180

The value of 5 digits after the decimal point: 0.61803

The value of 7 digits after the decimal point: 0.6180340

(Note the 0 at the end, which cannot be ignored)

 

Your task is: write the golden ratio value accurate to 100 digits after the decimal point

Note: the mantissa is rounded off! Keep the mantissa 0!

Obviously the answer is a decimal, with 100 digits after the decimal point. Please submit the number directly through the browser.

Note: Do not submit the answering process or other supporting text

Problem-solving ideas:

According to the definition of the golden ratio, we can first introduce the first few items

It can be found that after the decimal is expressed as a fraction,

The numerator of the fraction = the denominator of the previous fraction,

The denominator of the fraction = the sum of the numerator and denominator of the previous fraction

This is in line with the characteristics of the "Fibonacci" sequence

The third number is equal to the sum of the first two numbers, and the golden ratio is equal to the quotient of the two numbers

So according to this feature, we can calculate higher precision data

At the same time, it should be noted that the ten digits after the decimal point have exceeded the range of double, so biginteger and bigdecimal should be used to represent data

Answer source code:

package 一三年省赛真题;

import java.math.BigDecimal;
import java.math.BigInteger;

public class Year2013_Bt4 {

	public static void main(String[] args) {
		BigInteger a = BigInteger.ONE;
		BigInteger b = BigInteger.ONE;
		for (int i = 3; i < 300; i++) {
			BigInteger t = b;
			b = b.add(a);
			a = t;
		}
		BigDecimal divide = new BigDecimal(a,110).divide(new BigDecimal(b,110),BigDecimal. ROUND_HALF_DOWN);
		System.out.println(divide.toPlainString().substring(0, 103));

	}

}

 

Sample output:

There are deficiencies or improvements, and I hope my friends will leave a message and learn together!

Interested friends can follow the column!

Little Grey Ape will accompany you to make progress together!

Finally, I am participating in the selection of the 2020 Blog Star, please help me to vote for it!

Vote link: https://bss.csdn.net/m/topic/blog_star2020/detail?username=weixin_44985880

Guess you like

Origin blog.csdn.net/weixin_44985880/article/details/113000519