In the Maximize LCM question in March luchtime 2020,
For Python I got AC in Reduced Constraints and TLE in Original Constraints, while
For C++ I got WA in Reduced Constraints and WA in Original Constraints.
Both the Python and C++ codes have exact same logic, even exact same variables and syntax format, so it is easier to debug.
Can you help me out.
Python Solution
C++ Solution
The LCM is huge. In Python it times out because it’s working with enormous numbers, and in C++ it gets WA because it’s overflowing. You have to find the answer without directly computing the LCM.
2 Likes
Then why in Python it gives AC on reduced constraints and C++ it gives WA for reduced constraints.
Python doesn’t overflow because it expands the allotted memory of integers if they exceed it, giving them unlimited capacity (I’m not a Python expert, this is just a rough idea of why it doesn’t overflow). For reduced constraints, it just so happens that the LCMs are small enough that the program doesn’t time out. C++ limits integers to a certain amount of bits, and will simply overflow when the integers get big enough to a point where they exceed their limit. Because it’s overflowing, you get WA as the LCM isn’t what it’s supposed to be.
edit: to make this point, reduced constraints are still enough to cause overflow