TREE: WA answer

I am getting a wrong answer for the practice problem http://www.codechef.com/problems/TPRODUCT. Can anyone tell me the problem with my solution? It seems to be a pretty straightforward question and I am quite sure the logic I am using is correct…

my solution http://www.codechef.com/viewsolution/4847186

Thank you

these are 32 bit machines so use long long int instead of long int.
your logic for comparing two large numbers is not correct.
for example let a=2002,b=1003,m=1000;
here (a%m)<(b%m) that doesn’t mean that b>a.
see the explanation in editorial for comparing large numbers.
and also try to use predefined functions such as std::max() and std::pow()

1 Like