Time Limit Exceeded TLE

I dont understand how to reduce the time limit.
Please help
The Problem is Prime Generator

import java.io.*;

class ttt

{

 public static boolean isPrime(long number)
{

			if(number==1)
        		return false;
		for(int i=2; i<number; i++)
        {
        	
           if(number%i == 0)
           {
               return false; 
           }
        }
        return true;

    }
    public static void main (String[] args)throws Exception {
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		String s[]=new String[t];
		
		for(int l=0;l<t;l++)
		{
                    
			s[l]=br.readLine();
                    s[l]+=" ";
                    
                   
		}
                	
		
		for(int m=0;m<t;m++)
		{
                int x=0;    
		int i,e=0,st;
		long a[]= new long[s[m].length()];
                for(i=0;i<s[m].length();i++)
		{
			st=x;
			x=s[m].indexOf(" ",x);
			if(x==-1 || s[m].length()==1)
				break;
			x++;
			e=x;
			try
                        {
                        a[i]=Long.parseLong(s[m].substring(st,e-1));
                        }
                        catch(Exception ex)
                        { break;}
                
                }
		
		
		
		for(long k=a[0];k<=a[1];k++)
                {
                    if(isPrime(k))
                        System.out.println(k);
                }
                System.out.println();
		
                }}
	}

Because, there are better known algorithms for checking whether a number is prime or not. Kindly read Sieve of Eratosthenes, and then Sieve of Atkins and try to implement these yourself. Then you might want to read some probabilistic methods also e.g. Miller Rabin Primality Test.

1 Like
//