Check divisibility of each line in a large dataset
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.