Vrutik_2809's blog

By Vrutik_2809, history, 22 months ago, In English

I was solving this problem. Although my solution is correct, I got TLE due to Java. My solution can be found here. But when i submitted the same solution in C++, it got accepted.(check it out here)

Can someone please help me out how to resolve this issue?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The issue is simply just that java is slower than c++. Without using some advanced factoring methods like pollard-rho, it might be impossible to solve that problem with java.

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

There's another blog post about Java performance when solving this particular problem: https://codeforces.net/blog/entry/110593

You can also always go to https://codeforces.net/contest/1771/status and filter the accepted solutions by the used programming language. You will see that there are some successful Java submissions. So solving it using Java is not impossible in principle.

But yes, Java users are generally at a disadvantage because of their programming language choice. Consider this as an extra challenge or try switching to a different programming language. C++ was always extremely popular in competitive programming. Rust is steadily gaining users too. And there are some other good choices.