What purpose does the result
array serve? You are only ever indexing into it to store the number you just parsed, and then immediately again to check its divisibility. Get rid of the array, and make the loop just:
while(n-- > 0)
if (Integer.parseInt(bi.readLine()) % k == 0)
divided++;
You may wish to compare its performance without the
BufferedReader
, since the buffering might actually be what's slowing it down.
Personally, I would use the Java 8 Streams API to do this, because it is easy to make it a parallel operation. Something like this:
Scanner input = new Scanner(System.in);
final int n = input.nextInt(), k = input.nextInt();
InputStreamReader in = new InputStreamReader(System.in);
System.out.println(
IntStream.generate(()->Integer.parseInt(in.readLine()))
.limit(n)
.parallel()
.filter(a->a%k==0)
.count());