1 / 4
Apr 2014

I don't really use Java but here are some possible optimizations.

Does the sqrt(x) change on every iteration of the loop? It will be evaluated at each check, so this wastes time.

What are you using the StringTokenizer for?

Is StringBuilder faster than multiple System.out.println()?

Hi Leppy,

I am using StringTokenizer to split the inputs by space and store in variables.

This program is taking 1s and is accepted in codechef.

Here the Time limit is 3s and still it is giving TLE.

multiple(100's+) System.out.println() will make the program slow, thats why StringBuilder to concat the result and giving output at one go.

I don't understand why you need to do this on this problem.

This is a different website. Why would you assume that everything is the exact same?

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.