Question DSA-MATH-0054
MediumWhy is (a − b) mod m computed as ((a − b) % m + m) % m in C++ or Java?
- A.
It avoids overflow
- B.
It isn't needed
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Math and Number Theory question
Why is (a − b) mod m computed as ((a − b) % m + m) % m in C++ or Java?
It avoids overflow
It isn't needed
Sign up free to see the answer and a step-by-step explanation.
It is faster
% can give a negative result for negative numbers in those languages