1 / 2
Nov 2017

I got time limit exceeded .
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{

     Scanner s = new Scanner(System.in);
     int t=s.nextInt();
     while(t>0){
     int m, n, flag = 0, i, j;
     m = s.nextInt();
     n = s.nextInt();
     if(m==1){
                      System.out.println("2");
     }
     for(i = m; i <= n; i++)
     {
         if( j = 2; j < i; j++)
         {
             if(i % j == 0)
             {
                 flag = 0;
                 break;
             }
             else
             {
                 flag = 1;
             }
         }
         if(flag == 1)
         {   
             System.out.println(i);
         }
         }
     t--;
}
}

}

  • created

    Nov '17
  • last reply

    Nov '17
  • 1

    reply

  • 1.0k

    views

  • 2

    users

  • 1

    link