How to decide a data type as int or long long from the given constraints?

In the problem Winning CB Scholarship, the constraints are:
1 ≤ N,M,X,Y ≤ 10^9​​

initially, I took int as data type, but couldn’t pass all the test cases. then I changed the data type to long long. After that, all test cases got passed.

So my simple question is how to decide the data type as int or long long by looking towards the constraints?

Usually constraints give you a good idea, but sometimes you maybe doing a multiplication of two integer data types and that may give you an overflow. So it varies from problem to problem.
For example finding factors using sieve.

@keshavgupta0103 Can you tell what should be the data type of N, M, X, Y in the above problem by looking towards the constraints (1 ≤ N,M,X,Y ≤ 10^9​​) with proper reason.

Of course you can use int. But if you are going to do something like N*N somewhere in your code then you need to use long int as it may overflow. Again it depends upon the solution you are writing.

Ohh okay, got it. Thanks.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.