I know the problem can be done using switch case very easily
Do it! I think that first thing you should try when you want to use super-weird solution is to have normal one.
your solution returns incorrect result for input
1000000001 * 1000000002 =
and throws exception for
There are some micro optimizations you can do, but why to do those, when probably
engine.eval() call is the “bottle neck”?
What would you answer to someone if he/she asks: “Hello guys, my program is getting TLE. I know it can be easily done using scanf and printf, but I learnt about cin/cout recently and want to apply it for this particular program.”?
I do not want to be rude, but this is very typical for newbies: “Guys, what is the fastest I/O reading operation, because my O(N^2) solution is getting TLE for N=1000000…”, see?
If you have working (AC) version, than you can do some experiments how much slower this revolutionary approach of using ScriptEngineManager is, for some big N, let say 100000 and input file is
1 * 2 =
2 * 3 =
100000 * 100001 =