Today I was solving this problem.
I made two similar submissions.
Sub1 used class ( TLE ).
Sub2 exact same code without class ( AC ).
I can't understand why making the functions and variables as class's member consuming so much time?
I have googled but didn't find anything written about it.
Have you tried to benchmark the programs locally against each other and figure out exactly what slows down the execution?
No. Actually, I don't know how to do this.
Your mod variable changes from a constant to a variable and compilers are very good at optimizing constant modulus / division operations whereas variable ones are slow.
WOW !
Didn't know about it.
I just got Accepted. const mod
Thanks a lot.