use of long int in c and c++

Heading #### Does use of "long long"instead of “int” affect the execution time of a source code.

(All the values are in range of “int”)

1 Like

What do you mean by o/p time.

@coder_voder sometimes using long causes TLE like in (DEC16/BASE)
but only using int pass all test cases.

I cannot say about TLE but it increases computation time , have noticed this in c++ in which while calculating GCD if we change datatype form int to long long or long long int o/p time increases.

In my opinion, it’s better to use int rather than long or long int as firstly, takes longer to type, and moreover some functions and compilers have varying behaviour with long; most are clearly defined for int similarly everywhere.
Example: Some systems have 64 bit long, UNIX; the built-in functions support int only mostly

This applies to “long or long int”. long long int on the other hand is a entirely different thing.

1 Like

@only4 You can refer to this answer, it clearly explains that why taking long long int causes TLE sometimes. Also sometimes using mod () operator freely causes TLE, as mod () operator involves division, multiplication and subtraction.

x % y = x - ( x / y ) * y

So, instead of applying a mod (%) directly, you can use a condition that whether it is required or not,

Eg:

if(x>=y)
x%=y

2 Likes

takes longer to type??? you can use typedef long long ll;

He’s talking about long which is a disguised int/long long int depending upon platform. The typing thing doesn’t make any difference.

Wait, I requires functions?

yes, it does increase the time of execution of code as it has more memory space alloted for this long long data type.

Please paste both the solutions where you got stuck because of long long data type! Thank you