0

Given input x,and array [a1,a2,a3..an], is it possible to find max number of which x is factor in log(n) time.

For example x = 2,

array is sorted, [1,2,4,4,9,13,18],

Here maximum number of which x is factor is 18. Is it possible to find 18 in log(n) time.

amit
  • 1

1 Answers1

-2
import java.util.ArrayList;
import java.util.Collections;
public class HelloWorld{

     public static void main(String []args){

          ArrayList<Integer> al2 = new ArrayList<Integer>();
         int a =4;
         int[] b={40,2,12,8,24,13,18};
        for(int j=0;j<b.length;j++)
         {
             if(b[j]%a==0)
             {
                al2.add(b[j]);
               Collections.sort(al2);
               }
         }
     System.out.println(al2.get(al2.size()-1));
     }
}