We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #65: Convergents of e
Project Euler #65: Convergents of e
Sort by
recency
|
12 Discussions
|
Please Login in order to post a comment
Python 3 solution, using the fact that the continued fraction of e has a pattern of 2 1 1 4 1 1 6 11, ..., from index 2:
python solution
Java BigInteger
Observed patterns how the fraction changes from the required convergent to back to 3rd convergent.
I handle the 1st and 2nd convergents explicitly. I represent the fraction using two variables num and den which stand for numerator and denominator.
First, I find out which multiple of 2 in the series is the closest to the required convergent. for example, if the required convergent is 10, then I make the fraction ready for calculation from '6' in the series. The variable a denotes the next multiple of 2 coming up in the series. for example, the fraction i prepared for convergent 10 was built using '6', but the next multiple of 2 in the series will be 4, so I assign a as '4'. I also made two functions, one: to "add an upcoming number" (whether 'a' or 1) to the fraction and two: to find the "reciprocal" of the fraction and then dividing the reciprocal by 1. (swapping num and den) The rest is pretty much self explanatory
This was my code when I thought long would be enough:
But obviously that did not work out as the numbers go way crazy! Then i converted the above same logic into BigInteger. Here it is:
Drop any queries in the comments, thanks ^__^
easiest one, read out https://en.wikipedia.org/wiki/Continued_fraction Hope you will find an interseting sequence :)
numerator of 1000th convergent of e is 215043704928079275546350787635650473761037041054859471165269502507479923032839714356724383714831841317366238276604523416281523473735321526891502403788816357622379442531491479026711305726965718338010987910057233389226490407411089485760896902310261221862678564406652752374955049717966691207750626672828237587801856684747486631597540991685830010525355010719203587499740078562960236843126355248620564746559167769326909433896876227967966175044435184104070710491139996424638579352260315417440334385948582209795598793930287323042471339820970546936086378376760534212782350052379307682063245509120325519354493739145354196963988176021541799313848844519348782087171841449631173955150527331688172773011269564741846170156748881775468801141386665111250188282655381313977369237039915405910733421356869262135558938824245060650524874574094964353159517730092429834471126538079994918145838803922920707615406623257756931
But my program gives different value,I don't know why? I used BigInteger and equals method to check.