title: Remove all the multiples of a given set of numbers from given range
body: <p>I am stuck on a problem, where it says, given a number <code>N</code> and a set of numbers, <code>S = {s1,s2,.....sn}</code> where <code>s1 &lt; s2 &lt; sn &lt; N</code>, remove all the multiples of <code>{s1, s2,....sn}</code> from range <code>1..N</code></p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>Let N = 10
  S = {2,4,5}
  Output: {1, 7, 9}
  Explanation: multiples of 2 within range: 2, 4, 6, 8
               multiples of 4 within range: 4, 8
               multiples of 5 within range: 5, 10 
  </code></pre>
  
  <p>I would like to have an algorithmic approach, psuedocode rather than complete solution. </p>
  
  <p><strong>What I have tried:</strong></p>
  
  <pre><code>(Considering the same example as above) 
  
   1. For the given N, find all the prime factors of that number.
      Therefore, for 10, prime-factors are: 2,3,5,7
      In the given set, S = {2,4,5}, the prime-factors missing from 
      {2,3,5,7} are {3,7}.  
   2. First, check prime-factors that are present: {2,5}
      Hence, all the multiples of them will be removed 
      {2,4,5,6,8,10}
   3. Check for non-prime numbers in S = {4}
   4. Check, if any divisor of these numbers has already been 
      previously processed.
           &gt; In this case, 2 is already processed.
           &gt; Hence no need to process 4, as all the multiples of 4 
             would have been implicitly checked by the previous 
             divisor.
      If not,
           &gt; Remove all the multiples from this range.
   5. Repeat for all the remaining non primes in the set.
  </code></pre>
  
  <p>Please suggest your thoughts!</p>