time limit exceeded

All general topics that Dev Skill members should discuss.

time limit exceeded

by arabin » Sun Aug 07, 2016 12:43 pm

Is it prime problems solutions show time limit exceeded but my code is perfect i think

Code: Select all
import java.util.Scanner;

/**
 *
 * @author arabin
 */
 class MyClass {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
       
        Scanner kbScanner = new Scanner(System.in);
        int test = kbScanner.nextInt();
        String []answer = new String[test];
        if (test>0) {
            for (int i = 0; i <test ; i++) {
                answer[i] = primeDecision(kbScanner.nextInt());
            }
        }
        for (int i = 0; i < answer.length; i++) {
            System.out.println(answer[i]);
        }
    }

    private static String primeDecision(int nextInt) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
       
        if (nextInt == 2) {
            return "Yes";
        }
        else{
            for (int i = 2; i <nextInt ; i++) {
            if (nextInt%i == 0 ) {
                return "No";
            }
        }
    }
    return "Yes";
    }
   
}
 
Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

Re: time limit exceeded

by devskill » Sun Aug 07, 2016 4:10 pm

Java is damn slow :) Increased time limit for java. please try again.
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: BryanStuck and 1 guest
cron