[JAVA] [2013 Blue Bridge Cup preliminary Java Undergraduate B group] [Gold even score]

Source: Internet
Author: User

title: Gold even score


Golden Divide number 0.61803 ... is an irrational number, this constant is very important and will arise in many engineering problems. Sometimes it takes a lot of precision to figure this out.


for some precision engineering, the precision of a constant is important. Perhaps you've heard of the Hubble Space Telescope, which, after its first launch, found an artificial fabrication error,


in fact, mirror processing when there are more than the head of the hair is a lot more than a mistake, but make it a "myopia"!


So, how do we get the best possible value for the Golden segment number? There are many ways.


a relatively simple one is to use a hyphen:


1
number of gold =---------------------
1
1 +-----------------
1
1 +-------------
1
1 +---------
1 + ...
                   
The greater the number of "layers" that the even fraction calculates, the closer the value is to the Golden segment.


take advantage of this feature to find enough accurate values for the golden segment to be rounded up to 100 decimal places.


the 3-bit value after the decimal point is: 0.618
the 4-bit value after the decimal point is: 0.6180
the 5-bit value after the decimal point is: 0.61803
the 7-bit value after the decimal point is: 0.6180340
(note the trailing 0, cannot be ignored)


your task is to write a golden segment value that is accurate to 100 digits after the decimal point.


Note: The mantissa is rounded! The mantissa is 0 also to keep!


Obviously the answer is a decimal number, which has 100 digits after the decimal point, please submit the number directly through the browser.

Note: Do not submit the content of the answer process, or other auxiliary description classes.



[Java]View Plaincopyprint?
  1. import  java.math.bigdecimal;  
  2.   
  3. public   class  main {  
  4.   
  5.      public   static   void  main (String[] args)  {  
  6. BigDecimal bd = new BigDecimal (1);
  7. for (inti =0; i < +; i++) {  
  8. BD = Bd.add (Bigdecimal.one);
  9.             bd =  bigdecimal.one.divide (Bd, 102 , bigdecimal.round_half_down );   
  10. }
  11. System.out.println (Bd.tostring ());
  12. }
  13. }

last year with C Leng did not write out, now look at Java is 10 lines not to ...

The answer is

0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375

[JAVA] [2013 Blue Bridge Cup preliminary Java Undergraduate B group] [Gold even score]

Related Article

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.