title: Number of non repeat divisible dividends (optimize)
body: <p>Is there a way to improve my algorithm to get the optimal one in terms of computing time?</p>
  
  <p>Given a range of non-zero dividend numbers [A,B] (1&lt;=A,B&lt;=10^18), and a set of divisors D = {x: 1 &lt;= x &lt;= 50}, I want to find the total number of non-repeating dividends in [A,B] that can be divided by any number in set D.</p>
  
  <p><strong>Example 1 (doesn't take too much time)</strong></p>
  
  <p>The range of dividend numbers <code>[1,10]</code> and the divisors are <code>{2,3,4}</code></p>
  
  <ul>
  <li>list of numbers divisible for divisor 2: <code>2,4,6,8,10</code> </li>
  <li>list of numbers divisible for divisor 3: <code>3,6,9</code> </li>
  <li>list of numbers divisible for divisor 4: <code>4,8</code></li>
  </ul>
  
  <p>So the total number of non-repeat divisible dividends in <code>[1,10] = 7</code></p>
  
  <p><strong>Example 2 (takes a lot of time)</strong></p>
  
  <pre><code>[A,B] = [79031836253224256, 403892407826392155]
  D = {44, 46, 50, 8, 35,41,6,18, 24, 23, 7, 45, 39, 46, 4, 35, 34}
  Output: 161802330522861274
  </code></pre>
  
  <p><strong>1st version of the algorithm in Python</strong></p>
  
  <pre><code>def solution(A,B,D):                                                                                                                                                                         
      a = set()                                                                                                      
      for i in range(A,B+1):                                                                                         
              for j in D:                                                                                            
                      if i%j == 0:                                                                                   
                              a.add(i)                                                                               
      # return the count of a                                                                                        
      return len(a)   
  
  if __name__ == "__main__":                                                                                             
          print(solution(1,10,[2,3,4]))                                                                                  
  </code></pre>