Comments

The IO you are doing is slow; instead of Scanner, try BufferedReader,instead of System.out, Use PrintWriter.

CAN ANYONE TELL WHAT'S GOING WRONG WITH THIS CODE, GETTING WRONG ANSWER IN TEST CASE 2 : int t=(int)Math.sqrt(n)+1; int divisor=1; for(int i=Math.min(k,t);i>0;i--){ if(n%i==0){ divisor=i; break; } } if(n/divisor<=k) System.out.println(divisor); else System.out.println(n/divisor);