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.