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.
A and B <= 10**18 that means the biggest sum of digits is 999 999 999 999 999 999 (i.e 18 nines). So the biggest number to check as prime is the sum of eighteen squares of nines:
9*9*18=1458
spoiler: 1458 is not prime but 231 numbers below 1458 are prime. Not too many... to store in a list. You can calculate them or copy from here or whatever source you choose:
Checking if number is in the list of primes will save you a for loop check, reducing therefore time complexity of your code.
Another spoiler: although it is more efficient than a foor loop prime checker, this won't save you to timeout if you loop between A =1 and B =10^18 stepping +1.
Edit: as stated by @abhiranjan 4 years ago 10^18 instructions may take ~316 years to solve by modern computers. Even them where 32 years or 3 years is unpractical to wait compute that long.
Lucky Numbers
You are viewing a single comment's thread. Return to all comments →
If my calculations are right...
A and B <= 10**18 that means the biggest sum of digits is 999 999 999 999 999 999 (i.e 18 nines). So the biggest number to check as prime is the sum of eighteen squares of nines:
spoiler: 1458 is not prime but 231 numbers below 1458 are prime. Not too many... to store in a list. You can calculate them or copy from here or whatever source you choose:
Checking if number is in the list of primes will save you a for loop check, reducing therefore time complexity of your code.
Another spoiler: although it is more efficient than a foor loop prime checker, this won't save you to timeout if you loop between A =1 and B =10^18 stepping +1.
Edit: as stated by @abhiranjan 4 years ago 10^18 instructions may take ~316 years to solve by modern computers. Even them where 32 years or 3 years is unpractical to wait compute that long.
We need something better.