I know Sieve of Eratosthenes but I am not able to solve this problem. How can I solve this problem using Sieve.