Jump to content
BrainDen.com - Brain Teasers
  • 0

A Complicated Numbers Problem


gavinksong
 Share

Question

This is another problem from Google Code Jam that blew my mind.
It is still blowing my mind. It just so happens to be from the same round as the problem I posted earlier.
 

  Quote

Problem
In this problem, you have to find the last three digits before the decimal point for the number (3 + √5)n.


Like before, there is a small input and a large input for this problem. For the large input, n can reach up to 2 billion. Thus, in order to calculate the answer in a reasonable amount of time (and precision*), some key mathematical insights are required.

 

What are they?

 

*for non-coders: since computers cannot store real numbers with infinite precision, most operations on "floating point numbers" cause a gradual loss in precision. In our case, it would almost definitely result in an incorrect answer.

Link to comment
Share on other sites

Recommended Posts

  • 0

First count (sqrt 5), in very high precision.

Then use pascal triangle formula.

then group every odd exponent of sqrt (5). then multiple it by (sqrt 5) just once, you will get right answer.

you will get better precision.

example

(a+b)5 = a5 + 5a4b + 10a3b2 + 10a2b3 + 5ab4 + b5

         = a5 + b(5a4 + 10a2b2 +b4) + 10a3b+ 5ab4

(3 + √5)5 = 35 + √5(5.34 + 10.32.5 + 25) + 10.33.5+ 5.3.25 = 1968 + √5*880 

Link to comment
Share on other sites

  • 0

I think I have found the answer

  Reveal hidden contents

 

Link to comment
Share on other sites

  • 0
  On 2/2/2016 at 9:18 PM, mmiguel said:

 

  Reveal hidden contents

 

Expand  

Nice job! As you said, our fellow brain-denizens had all the bits and pieces (especially DeGe and Logophobic, also Molly Mae). Well done on putting them all together!

There IS one last piece of the puzzle required to make n = 2 billion run in a reasonable amount of time.

  Reveal hidden contents

 

Link to comment
Share on other sites

  • 0
  On 2/2/2016 at 9:18 PM, mmiguel said:

 

  Reveal hidden contents

 

Expand  

Nice job! As you said, our fellow brain-denizens had all the bits and pieces (especially DeGe and Logophobic, also Molly Mae). Well done on putting them all together!

There IS one last piece of the puzzle required to make n = 2 billion run in a reasonable amount of time.

  Reveal hidden contents
  On 12/30/2015 at 12:47 AM, Logophobic said:

 

  Reveal hidden contents
Expand  

I didn't know this. If this is true, this is indeed an alternative solution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...