[WA] with C/C++ but [AC] with Python

I have noticed that whenever I write a program in C/C++ which involves modulo operated long long or unsigned integers, I end up getting WA. But when I submit the same code in python I get AC. Does modulo work differently with unsigned and long long ints ?

Eg:- Python :- http://www.codechef.com/viewsolution/6931889
C :- http://www.codechef.com/viewsolution/6931649

Hey, well i don’t know case of python, but there is problem with your code in c/c++, when you do something like (sum - term)%mod, if sum -term is negative, you’ll get different answer, maybe in python they convert the expression to positive and then take modular, if we do it like this, (sum + mod - term)%mod, there won’t be any problem in c/c++

check this , AC with your solution after adding mod in expression where minus in used.

http://www.codechef.com/viewsolution/7331807 :slight_smile:

2 Likes
//