Blue Bridge Cup fourth set of Java Gold continued fraction

Blue Bridge Cup fourth set of Java Gold continued fraction
 

description

 

Golden number 0.61803 ... is an irrational number, this constant is very important, it will appear in many engineering problems. This number is sometimes necessary to seek very accurate. For certain precision engineering, precision constant is very important. Perhaps you have heard of the Hubble Space Telescope, launched after it was first discovered an artificial processing errors, like a monster, but in fact there is an error thinner than a human hair are many times when a mirror finish it, while filling it became the "myopia" !! Closer to home, how can we obtain as precise value of the golden it? There are many ways. One is to use a relatively simple continued fraction:

              1
黄金数 = ---------------------
                    1
         1 + -----------------
                      1
             1 + -------------
                        1
                 1 + ---------
                      1 + ...

The score calculation is even more "layers", its value is closer to the number of divisions gold. Please take advantage of this feature, obtain a sufficiently accurate value of the golden section 100 requires rounding to one decimal. Three decimal places value: 4 The value of 0.618 after the decimal point: 5 value of 0.6180 after the decimal point: 0.61803 after the decimal point seven values: 0.6180340 (Note 0 tail, can not be ignored) Your mission is to: write golden value 100 decimal place accuracy. Note: rounding the mantissa! Ending in 0 also reserved! Obviously the answer is a decimal, there are 100 numbers after its decimal point, please submit directly to the number.

 

Entry

 

No input.

 

Export

 

Write golden value 100 decimal place accuracy. Note: rounding the mantissa! Ending in 0 also reserved! Obviously the answer is a decimal, there are 100 numbers after its decimal point, please submit directly to the number.

 

Sample input 1 

no

Sample Output 1

   no

This question, that is difficult is difficult, there are several ideas, after all, is a 1/1 + x.

The first is near to the minimum and maximum x, value of each layer of view.

The second is as a dash divided entirely omitted below;

Both can be found a pattern,

Finally obtained two adjacent relationship x / y, y / x + y;

Such conventional can be pushed back, the more accurate the more pushed back.

 

Then it is to be noted that this is certainly not to save up 100 decimal.

An integer by another integer, floating-point addition directly converted to decimal division obtained. Another way is to simulate the hand count, the first is divisible, then the remainder * 10 continue divisible;

Note: a lot of answers on the network is not available, if the simulation manually, which was a bit pushed down, there is no rounding. So as to pay only answer a question, you have to push to 101, and then judge for yourself four or five rounds into;

Code

package test;


import java.math.*;
public class Main5 {

static void main public (String [] args) {
a BigInteger firstNum = BigInteger.ONE; //. 1
a BigInteger SECNUM = BigInteger.ONE;
a BigInteger RES = BigInteger.ZERO; 0 //
a BigInteger TEN = BigInteger.TEN; 10 //

// BigInteger columns of Fibonacci numbers
for (int I = 0; I <50000; I ++) {
IF (I == I == 0 ||. 1) {
RES = BigInteger.ONE;
}
RES = secNum.add (firstNum) ; // adding two BigInteger
firstNum = SECNUM;
SECNUM RES =;
}

// for loop simulation achieved hand count divider
for (int i = 0; i <102; i ++) {// 101 bit before the show, because it is seek out one by one, not round, so more for one, one should not look at the front plus a
deed in two consecutive Fibonacci numbers selected // do small dividend, division by large
// every value is the quotient of the two
BigInteger ANS = firstNum.divide (SECNUM);
// constant divisor, dividend remainder * 10 =
= firstNum (firstNum.mod (SECNUM)) Multiply (TEN);.
IF (! I = 0) {// Only after the decimal point of output 100
of System.out.print (ANS);
}
}
System.out.println ( );

}
}

 

Results: 61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748

Submit Answers: 0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375

Guess you like

Origin www.cnblogs.com/zsboke/p/11980442.html