Euler Sum-JUNE LONG

I used the Euclidean-based algorithm for computing the floor sum and also used spigot algorithm to compute e upto 9000 decimal digit.

I also optimized basic Spigot to compute e faster and it takes about 3sec but my code takes 20 sec for 10^4000.

I would be grateful if someone could figure out what improvement could I have done to my code.

I read similar questions on that but can’t figure out why the similar approach used by other passes in time.

Click Here to view my solution.

I tried optimizing your code (turned it to while loop, avoided divisions) but to no avail, still TLE.

My conjecture is that your code is getting time limit since it’s doing twice the number of work since there’s both left pointer and right pointer. Maybe try reducing to one pointer only?