Solved Problem - Segmented Sieve
In this lesson, we'll discuss how to implement the segmented Sieve: a very popular variation of sieve.
We'll cover the following...
Problem statement
Given two integers, and , print all primes between and (both inclusive).
Input format
The only line of input contains two integers and .
Sample
Input
100000000 100000100
Output
100000007 100000037 100000039 100000049 100000073 100000081
Sieve
Obviously, Sieve of Eratosthenes comes to mind. Now, two things don’t work right here:
- , we don’t have enough memory to declare an array of a billion integers (4 GB memory).
- Even if we could declare an array that big, the time complexity would be , which is obviously very slow.
Observation: