[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 :- CodeChef: Practical coding for everyone
C :- CodeChef: Practical coding for everyone

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.

CodeChef: Practical coding for everyone :slight_smile:

2 Likes