Int vs long

Hey I’m new to programming and recently started using codeChef for coding practice.
I’m currently making easy level problems, and I am now comfortable with it, hence I want to move to the next difficulty.
But only one thing is stopping me.
I’m having trouble in making decision between “long” and “int”.
I’m not able to know when to use int and when to use long and how to identify it by reading the problem.
In recent 4-5 problems it was giving me errors just because of it.
And also how can I know, how to manage program running time and memory limit.
Please help me. :slight_smile:

This is a hack which I regularly use hope it helps you too like whenever there is constraint
1.upto 10^9 use int
2.upto 10^12 use long
3.upto 10^18 use long long int
Don’t just consider initial constraints do consider the cases when iterating through loops and adding numbers.
Always while considering the time complexity keep in mind that in general computer can run 10^8 operations in a second (maybe 10^9) in some cases this is usually the common constraints in online judges so try to code accordingly.Hope this answers your query.

3 Likes

thanks for helping dude.

Welcome :smiley: