Calculating sum of smallest prime factors for 2 < n < 10**12
Sorry, too long for a comment (this isn't a real review, but it isn't a CR what you need).

This is Project Euler 521 and providing a full answer here would spoil the fun. If you really want to cheat, google it out.


  Is there any way to shorten the runtime of this program?


There are many ways and you'll need more than one:


Iterating till 10**12 alone is too slow, even if you did just a simple sum (one hour maybe).
Determining if a number is a prime, even with a good sieve takes quite some time as well.


Without much thinking, I agree with you that the runtime will be many days.



Your question is actually not about code optimization, but about finding a smarter algorithm. Smarter by a few orders of magnitude. A wonderful hint can be found in forum for problem 10, page 5.

It's solvable without this wonderful idea, too, but it took my computer half an hour. Instead of factoring numbers, I produced them as products, which is much faster when you really want all of them. The next idea is that you don't really need to produce them, counting is enough.