Take the following problem: “how many numbers are in a given range of integers, from which both their sum of digits and the sum of its square are prime?”
I was watching around codereview, and here I found an interesting question and tried to solve it.
So one can check prime numbers in a ordinary fashion, i.e. using a for loop from 2 to i and check for divisibility.
The interesting thing is here. BlueRaja - Danny Pflughoeft suggests a trick: “Since you only need to sieve to the square root of the number you’re testing for primality, you only need to run your sieve from 3 to*sqrt(⌈log10(B)⌉*81)“.
I have a question regarding implementation of Sieve of Eratosthenes.
what is the size of boolean array, which contains numbers to process for sieve.? can somebody write a code or any hint?
Here’s an example of the implementation of the Sieve of Eratosthenes using Java: link.
For the second part of your questions see this link: