Check divisibility of each line in a large dataset I have solved this assignment in online coding community, and it has run successfully. But it's showing 12.09s of execution.
How could this be optimized ?

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.
Input
The input begins with two positive integers n k (n, k&lt;=10^7). The next n lines of input contain one positive integer t(i), not greater than 10^9, each.
Output
Write a single integer to output, denoting how many integers t(i) are divisible by k

import java.util.*;
import java.io.*;

class InputTest{

public static void main(String args[]) throws Exception{

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    String arr[]=br.readLine().split(&quot; &quot;);
    int n=Integer.parseInt(arr[0]);
    int k=Integer.parseInt(arr[1]);
    int count=0;

    if(n&lt;=0 || k&lt;=0 || k&gt;Math.pow(10,7)){
        throw new Exception();
    }
    else{

        for(int i=0;i&lt;n;i++){
            int m=Integer.parseInt(br.readLine());
            if(m&gt;Math.pow(10,9))
                throw new Exception();
            if(m%k==0)
                count++;

        }
        System.out.println(count);
    }


}
}
class InputTest{


Spacing.

public static void main(String args[]) throws Exception{


Again. There should be a space before each "{".

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


You're using a platform dependent encoding (which is actually nearly always wrong). There are chances that it's UTF-8 and it probably takes quite some time.

Nearly any encoding would do, and e.g., LATIN-1 should be faster as it converts one byte to one char, which is way simpler than UTF-8.

But even faster would be no encoding at all. The whole input can be easily read directly from bytes.

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


Spaces are inexpensive, use them! No more comments on formatting.

if(m&gt;Math.pow(10,9))


Gotcha! Why are you exercising such an expensive operation every time? And why do you wonder that it's slow? Maybe the JIT may be able to optimize it away, but


You could simply 1e9 and get rid of the computation.
You could simply write 10000000 or (since Java 7) even 10_000_000 and have an integer as it should be.
But you surely should define a constant instead. The it doesn't matter how complicated the computation is as it gets done just once.

throw new Exception();


That's ugly. Exception is too unspecific and there's no message there. What about a

throw new RuntimeException(String.format("Invalid (k, n) = (%s, %s)", k, n));


Or would maybe

assert n &gt; 0 : n;
assert k &gt; 0 : k;
assert k &lt;= 10_000_000 : k;


do?



So again, if you want to speed it up,


remove the obvious inefficiency
don't use strings
read the file in as a byte[]
parse numbers from it manually




For really big inputs, it could make sense to avoid both the conversion to int and the modulo computation by creating a data structure working directly with the input byte[]. But this is rather complicated , surely not for everyone.