Date: 18/06/2026 11:14:40
From: The Rev Dodgson
ID: 2402063
Subject: re: Chat June 2026

Michael V said:


The Rev Dodgson said:

But enough of this Hanson chat.

I’m sure you will all be thrilled to know that in order to avoid doing anything useful I am calculating the sum of the prime numbers between 1,000,000,000,000 and 1,000,000,100,000, using Excel (with a little help from Python).

!!!

Here’s what prompted me to do this little exercise:

“What is the sum of all prime numbers between 1,000,000,000,000 and 1,000,000,100,000?

3614000181007876

A modification of Sieve of Eratosthenes will help you solve the problem. First thing to note is that, if any number between 10^12 and 10^12+10^5 is composite, it will have at least one prime factor smaller than 10^6. This is because, if N is a composite number, the second largest prime factor of N will necessarily be less than or equal to sqrt(N). So we just need to sieve out these prime factors.”

I had hoped I might get a different answer, but after realising that Excel was rounding my result to 15 SF, so I should return the result as a string, I got exactly the same, so it could be right.

With a bit of code modification I did manage to get the execution time down from 90 seconds to 4.8 seconds, so that’s something.

Reply Quote View full thread