Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Time Limit Exceeded TLE

$
0
0

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();

                }}
    }

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>