CHEFING and the subtask 2 task 1

I am getting WA for subtask 2 task 1 for CHEFING in C++. But for the same code in python I got AC.

Can you provide the link ?

C++ code
Python code

Read Modular multiplicative inverse from here

Python does this by default. In C++, you have to code it out :slight_smile:

Check my C++ code here to understand better.

From your codes I expected it would do reverse. :sweat_smile:

Okk For C++ as someone mentioned about modular inverse. To eliminate that see that if num or a+l is even
let x = a+l
if num even num/=2
else x/=2
sum = (num%m)*(x%m)%m
Modified AC code of yours

1 Like

What would it reverse?

Actually you did float division in python and integer division in C. and ans is accurate mostly in integer division. But it was that modular inverse that created problem in C.

But how the code got accepted in python?

Yes, even I had the same issue.

actually what @debarya_452 did was simple.

Mine too python code got accepted :sweat_smile:. But I did all integer division. @nuttela said python does automatic modular inverse maybe that could be it.

Can you send your python code?
I did divide by 2 first in bracket to remove that modular inverse thing tho overflow no problem