title: Find the sum of all numbers between 1 and N divisible by either x or y
body: <p>Say we have <code>3</code> numbers <code>N</code>, <code>x</code> and <code>y</code> which are always <code>&gt;=1</code>.</p>
  
  <p>N will be greater than <code>x</code> and <code>y</code> and <code>x</code> will be greater than <code>y</code>.</p>
  
  <p>Now we need to <strong>find the sum of all number between 1 and N that are divisible by either x or y</strong>.</p>
  
  <p>I came up with this:</p>
  
  <pre><code>sum = 0;
  for(i=1;i&lt;=N;i++)
  {
    if(i%x || i%y)
      sum += i;
  }
  </code></pre>
  
  <p>Is there a way better way of finding the sum avoiding the for loop?</p>
  
  <p>I've been pounding my head for many days now but have not got anything better.</p>
  
  <p>If the value of <code>N</code> has a upper limit we can use a lookup method to speedup the process.</p>
  
  <p>Thanks everyone.</p>
  
  <p>I wanted a C/C++ based solution. Is there a built-in function to do this? Or do I have to code the algorithm?</p>