title: Count the number of integers in an array divisible by a given query k
body: <p>In this problem I have a number of queries for which I have to output the count of <code>integers</code> in the <code>array</code> which is divisible by k(one of the queries).The <code>array</code> contains duplicate elements. I am trying to optimise the problem and my approach is given below :</p>
  
  <p>Code:</p>
  
  <pre><code>public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
       int[] ar={2,4,6,9,11,34,654,23,32,54,76,21432,32543,435,43543,643,2646,4567,457654,75,754,7,567865,8765877,53,2};
       int query=sc.nextInt();
       int length=ar.length;
       int count=0;
       for (int i=0;i&lt;query ;i++ ) {
          int x=sc.nextInt();
          for (int j=0;j&lt;length ;j++ ) {
              if(ar[j]&gt;x){
                  if(ar[j]%x==0){
                      count++;
                  }
              }
          }
          System.out.println("Count:"+count);
       }
  }
  </code></pre>
  
  <p>The above code gives the correct output, but the complexity is <code>O(query*length)</code> and what if the array size is much bigger,the program will <code>timeout</code>. </p>
  
  <p>Can anyone help me optimize the problem?</p>